func init() { /** * Controller & Action */ goku.Controller("home"). //Filters(new(TestControllerFilter)). // this filter is fot controller(all the actions) Get("index", func(ctx *goku.HttpContext) goku.ActionResulter { return ctx.Html("Hello World") }) // project root dir _, filename, _, _ := runtime.Caller(1) config.RootDir = path.Dir(filename) }
package controllers import ( "github.com/QLeelulu/goku" "github.com/QLeelulu/ohlala/golink" "github.com/QLeelulu/ohlala/golink/filters" "github.com/QLeelulu/ohlala/golink/models" "fmt" "net/http" "strconv" "time" ) var _ = goku.Controller("discover"). /** * 未登陆用户首页 */ Get("index", discover_index). /** * 未登陆用户首页 */ Get("loadmorelink", discover_loadMoreLink). Filters(filters.NewAjaxFilter()) // END Controller & Action // // 发现 首页
package controllers import ( "fmt" "github.com/QLeelulu/goku" "github.com/QLeelulu/ohlala/golink/filters" "github.com/QLeelulu/ohlala/golink/forms" "github.com/QLeelulu/ohlala/golink/models" "html/template" "strconv" "strings" ) var _ = goku.Controller("link"). /** * 查看某评论 */ Get("permacoment", link_permacoment). /** * 查看一个链接的评论 */ Get("show", link_show). /** * 提交链接的表单页面 */ Get("submit", func(ctx *goku.HttpContext) goku.ActionResulter { ctx.ViewData["Values"] = map[string]string{ "title": ctx.Get("t"), "context": ctx.Get("u"),
package controllers import ( "github.com/QLeelulu/goku" ) // home controller var _ = goku.Controller("home"). // index action Get("index", func(ctx *goku.HttpContext) goku.ActionResulter { ctx.ViewData["Message"] = "Hello World" return ctx.View(nil) })
Error("required", "新密码必须填写"). Error("range", "新密码长度必须在{0}到{1}之间").Field() newPwd2 := form.NewCharField("new-pwd2", "确认密码", true).Min(6).Max(30). Error("required", "确认密码必须填写"). Error("range", "确认密码长度必须在{0}到{1}之间").Field() // add the fields to a form form := form.NewForm(oldPwd, newPwd, newPwd2) return form } /** * Controller: user */ var _ = goku.Controller("user"). /** * 查看用户设置页 */ Get("setting", func(ctx *goku.HttpContext) goku.ActionResulter { user := ctx.Data["user"].(*models.User) return ctx.View(models.User_ToVUser(user, ctx)) }).Filters(filters.NewRequireLoginFilter()). /** * 更新用户基本信息 */ Post("update-base", func(ctx *goku.HttpContext) goku.ActionResulter {
"github.com/QLeelulu/ohlala/golink" "github.com/QLeelulu/ohlala/golink/filters" "github.com/QLeelulu/ohlala/golink/models" "github.com/QLeelulu/ohlala/golink/utils" "io" "os" "path" "regexp" "strconv" "time" ) /** * Controller: topic */ var _ = goku.Controller("topic"). /** * 话题列表页 */ Get("index", func(ctx *goku.HttpContext) goku.ActionResulter { topics, _ := models.Topic_GetTops(1, 30) ctx.ViewData["TopTab"] = "topic" return ctx.View(models.Topic_ToVTopics(topics, ctx)) }). /** * 查看话题信息页 */
//"github.com/QLeelulu/goku/form" "errors" "github.com/QLeelulu/ohlala/golink" "github.com/QLeelulu/ohlala/golink/filters" "github.com/QLeelulu/ohlala/golink/models" "strconv" "strings" "time" ) type FavoriteResult struct { Success bool `json:"success"` Errors string `json:"errors"` } var _ = goku.Controller("favorite"). /** * 用户收藏link的首页 */ Get("index", func(ctx *goku.HttpContext) goku.ActionResulter { u, _ := ctx.Data["user"] user := u.(*models.User) links := models.FavoriteLink_ByUser(user.Id, 1, golink.PAGE_SIZE) ctx.ViewData["Links"] = models.Link_ToVLink(links, ctx) ctx.ViewData["HasMoreLink"] = len(links) >= golink.PAGE_SIZE ctx.ViewData["UserMenu"] = "um-favorite" return ctx.Render("/favorite/show", nil) }).Filters(filters.NewRequireLoginFilter()).
type InviteResult struct { Result bool Msg string InviteUrl string } type InviteViewModel struct { Title string RegisterInviteRemainCount int } /** * vote controller */ var _ = goku.Controller("invite"). /** * 给指定的email发送邀请码 */ Get("email", func(ctx *goku.HttpContext) goku.ActionResulter { inviteModel := &InviteViewModel{"邀请", 0} var userId int64 = (ctx.Data["user"].(*models.User)).Id inviteModel.RegisterInviteRemainCount = models.RegisterInviteRemainCount(userId) return ctx.Render("/invite/show", inviteModel) }).Filters(filters.NewRequireLoginFilter()). /** * 给指定的email发送邀请码 */ Post("email", func(ctx *goku.HttpContext) goku.ActionResulter {
package controllers import ( "github.com/QLeelulu/goku" "github.com/QLeelulu/ohlala/golink/filters" // "github.com/QLeelulu/ohlala/golink/models" ) var _ = goku.Controller("host"). /** * 查看一个host下的链接 */ Get("show", func(ctx *goku.HttpContext) goku.ActionResulter { return ctx.View(nil) }).Filters(filters.NewRequireLoginFilter())
package controllers import ( "fmt" "github.com/QLeelulu/goku" "github.com/philsong/ohlala/golink/filters" "github.com/philsong/ohlala/golink/forms" "github.com/philsong/ohlala/golink/models" ) var _ = goku.Controller("api"). // Get("index", func(ctx *goku.HttpContext) goku.ActionResulter { return ctx.View(nil) }). /** * 获取一个链接的信息 */ Get("link_info", func(ctx *goku.HttpContext) goku.ActionResulter { return ctx.View(nil) }). /** * 提交一个链接并保存到数据库 */ Post("link_submit", func(ctx *goku.HttpContext) goku.ActionResulter { f := forms.CreateLinkSubmitForm() f.FillByRequest(ctx.Request)
// {1} will replace with the max range value, Error("range", "值必须在{0}到{1}之间").Field() // title title := form.NewTextField("title", "待办事项", true).Min(8).Max(200). Error("required", "必须填写事项内容"). Error("range", "字数必须在{0}到{1}之间").Field() // add the fields to a form form := form.NewForm(id, title) return form } /** * todo controller */ var _ = goku.Controller("todo"). // todo.index action Get("index", func(ctx *goku.HttpContext) goku.ActionResulter { todos, err := models.GetTodoLists() if err != nil { return ctx.Error(err) } // you can pass a struct to ViewModel // then you can use it in template // like this: {{ .Model.xxx }} return ctx.View(todos) }). /** * todo.new action
// band package controllers import ( "fmt" "github.com/QLeelulu/goku" // "gocbweb/models" "gocbweb" "gocbweb/models2" ) var BandController = goku.Controller("band"). Get("add", func(ctx *goku.HttpContext) goku.ActionResulter { ctx.ViewData["Title"] = "Adding A Band" locations := models2.GetAll(gocbweb.LOCTYPE) return ctx.View(locations) //return ctx.Html("not implemented") }).Post("verify", func(ctx *goku.HttpContext) goku.ActionResulter { ctx.ViewData["Title"] = "Verifying Band" name := ctx.Request.FormValue("name") loctype := ctx.Request.FormValue("loctype") var locationId string errorString := "no errors" switch loctype { case "existing": if ctx.Request.FormValue("location_id") == "" { errorString = "No location was selected" } else { locationId = ctx.Request.FormValue("location_id") }
package admin import ( "github.com/QLeelulu/goku" "github.com/QLeelulu/ohlala/golink/filters" ) var adminController *goku.ControllerBuilder = goku.Controller("_golink_admin"). Filters(filters.NewRequireAdminFilter()) // render the view and return a *ViewResult // it will find the view in these rules: // 1. /{ViewPath}/{Controller}/{action} // 2. /{ViewPath}/shared/{action} // func adminView(ctx *goku.HttpContext, viewData interface{}) *goku.ViewResult { // return ctx.RenderWithLayout("", "adminLayout", viewModel) // }
"github.com/QLeelulu/ohlala/golink/filters" "github.com/QLeelulu/ohlala/golink/models" "strconv" //"time" //"github.com/QLeelulu/ohlala/golink" //"html/template" ) type CommentHtml struct { Html string } /** * 评论 */ var _ = goku.Controller("comment"). /** * 加载更多评论 */ Post("loadmore", comment_LoadMore). /** * 收到的评论 */ Get("inbox", comment_Inbox).Filters(filters.NewRequireLoginFilter()) /** * 加载更多评论 */ func comment_LoadMore(ctx *goku.HttpContext) goku.ActionResulter { htmlObject := CommentHtml{""}
package controllers import ( "fmt" "github.com/QLeelulu/goku" "gomenu1/models" ) var HomeController = goku.Controller("home"). Get("index", func(ctx *goku.HttpContext) goku.ActionResulter { ctx.ViewData["Title"] = "CD Catalog Home Page" bands := models.GetAllBands() return ctx.View(bands) }).Get("genrelist", func(ctx *goku.HttpContext) goku.ActionResulter { ctx.ViewData["Title"] = "List of Genres" genres := models.GetAllGenres() return ctx.View(genres) }).Get("bygenre", func(ctx *goku.HttpContext) goku.ActionResulter { rawId := ctx.RouteData.Params["id"] genreId := models.ConvertToId(rawId) genreName := models.GetGenreName(genreId) ctx.ViewData["Title"] = fmt.Sprintf("%s Albums", genreName) ctx.ViewData["GenreId"] = genreId bands := models.GetBandsByGenre(genreId) return ctx.View(bands) })
import ( //"fmt" "github.com/QLeelulu/goku" //"github.com/QLeelulu/goku/form" "github.com/QLeelulu/ohlala/golink/filters" "github.com/QLeelulu/ohlala/golink/models" "strconv" //"time" "github.com/QLeelulu/ohlala/golink" ) /** * vote controller */ var _ = goku.Controller("vote"). /** * 投票链接 */ Post("link", func(ctx *goku.HttpContext) goku.ActionResulter { vote := &models.Vote{0, 0, false, "请求错误"} id, err1 := strconv.ParseInt(ctx.RouteData.Params["id"], 10, 64) votetype, err2 := strconv.Atoi(ctx.RouteData.Params["cid"]) var score int = 1 //vote up if votetype == 2 { //vote down score = -1 } var userId int64 = (ctx.Data["user"].(*models.User)).Id if err1 == nil && err2 == nil {
// album package controllers import ( "fmt" "github.com/QLeelulu/goku" "gocbweb" "gocbweb/models2" "strconv" ) var AlbumController = goku.Controller("album"). Get("index", func(ctx *goku.HttpContext) goku.ActionResulter { bandId := ctx.RouteData.Params["id"] bandDoc := models2.GetDoc(bandId) bandValue := bandDoc.Value.(map[string]interface{}) ctx.ViewData["Title"] = bandValue["Name"].(string) // ctx.ViewData["Name"] = bandValue["Name"].(string) // ctx.ViewData["Id"] = bandDoc.Id // albums := bandValue["Albums"].([]models2.Album) // albums := bandDoc.GetAlbums() return ctx.View(bandDoc) }).Get("add", func(ctx *goku.HttpContext) goku.ActionResulter { ctx.ViewData["Title"] = "Add Album" ctx.ViewData["Id"] = ctx.RouteData.Params["id"] genres := models2.GetAll(gocbweb.GENRETYPE) return ctx.View(genres) }).Post("verify", func(ctx *goku.HttpContext) goku.ActionResulter { ctx.ViewData["Title"] = "Verifying Album" rawId := ctx.RouteData.Params["id"] name := ctx.Request.FormValue("name")