• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang goku.Controller函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/QLeelulu/goku.Controller函数的典型用法代码示例。如果您正苦于以下问题:Golang Controller函数的具体用法?Golang Controller怎么用?Golang Controller使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了Controller函数的17个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: init

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)
}
开发者ID:jango2015,项目名称:goku,代码行数:14,代码来源:simple.go


示例2:

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
//

// 发现 首页
开发者ID:yonglehou,项目名称:ohlala,代码行数:31,代码来源:discover.go


示例3:

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"),
开发者ID:polaris1119,项目名称:ohlala,代码行数:31,代码来源:link.go


示例4:

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)
	})
开发者ID:QLeelulu,项目名称:goku-demo,代码行数:13,代码来源:home.go


示例5:

		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 {
开发者ID:cloudcache,项目名称:ohlala,代码行数:31,代码来源:user_setting.go


示例6:

	"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))

	}).

	/**
	 * 查看话题信息页
	 */
开发者ID:yonglehou,项目名称:ohlala,代码行数:31,代码来源:topic.go


示例7:

	//"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()).
开发者ID:yonglehou,项目名称:ohlala,代码行数:31,代码来源:favorite.go


示例8:

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 {
开发者ID:cloudcache,项目名称:ohlala,代码行数:29,代码来源:invite.go


示例9:

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())
开发者ID:yonglehou,项目名称:ohlala,代码行数:16,代码来源:host.go


示例10:

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)
开发者ID:cloudcache,项目名称:ohlala,代码行数:30,代码来源:api.go


示例11:

		// {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
开发者ID:hoysoft,项目名称:goku,代码行数:31,代码来源:todo.go


示例12:

// 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")
		}
开发者ID:rossalbertson,项目名称:gocbweb,代码行数:31,代码来源:band.go


示例13:

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)
	// }
开发者ID:yonglehou,项目名称:ohlala,代码行数:17,代码来源:base.go


示例14: comment_LoadMore

	"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{""}
开发者ID:yonglehou,项目名称:ohlala,代码行数:31,代码来源:comment.go


示例15:

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)
})
开发者ID:rossalbertson,项目名称:gomenu1,代码行数:26,代码来源:home.go


示例16:

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 {
开发者ID:yonglehou,项目名称:ohlala,代码行数:30,代码来源:vote.go


示例17:

// 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")
开发者ID:rossalbertson,项目名称:gocbweb,代码行数:31,代码来源:album.go



注:本文中的github.com/QLeelulu/goku.Controller函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang goku.Logger函数代码示例发布时间:2022-05-28
下一篇:
Golang log.Println函数代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap