當前位置: 首頁>>代碼示例>>Golang>>正文


Golang goku.Controller函數代碼示例

本文整理匯總了Golang中github.com/QLeelulu/goku.Controller函數的典型用法代碼示例。如果您正苦於以下問題:Golang Controller函數的具體用法?Golang Controller怎麽用?Golang Controller使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了Controller函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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


注:本文中的github.com/QLeelulu/goku.Controller函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。