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


Golang Context.Res方法代碼示例

本文整理匯總了Golang中github.com/hjin-me/banana.Context.Res方法的典型用法代碼示例。如果您正苦於以下問題:Golang Context.Res方法的具體用法?Golang Context.Res怎麽用?Golang Context.Res使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/hjin-me/banana.Context的用法示例。


在下文中一共展示了Context.Res方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: UsersCreatePage

func UsersCreatePage(ctx banana.Context) error {
	err := Auth(ctx, PrivilegeUserRead)
	switch err {
	case ErrNoPermit:
		return err
	case ErrNotLogin:
		http.Redirect(ctx.Res(), ctx.Req(), "/login?error&u=/cp/users", http.StatusFound)
		return nil
	case nil:
	default:
		return err
	}

	/*
		idStr, ok := ctx.Params()["id"]
		if !ok {
			http.Redirect(ctx.Res(), ctx.Req(), "/cp/users", http.StatusFound)
			return nil
		}
		id, err := strconv.ParseInt(idStr, 10, 32)
		if err != nil {
			http.Redirect(ctx.Res(), ctx.Req(), "/cp/users", http.StatusFound)
			return nil
		}
		u, err := user.FindOne(int(id))
		if err != nil {
			return err
		}
	*/
	u := 1
	layout := ThemeLayout{}
	layout.Content = ThemeBlock{theme.CP("user"), struct{ Info interface{} }{u}}
	return ctx.Tpl(theme.CP("layout"), layout)

}
開發者ID:hjin-me,項目名稱:HJinBlog,代碼行數:35,代碼來源:users.go

示例2: Post

func Post(ctx banana.Context) error {
	err := Auth(ctx, PrivilegePostRead)
	switch err {
	case ErrNoPermit:
		return err
	case ErrNotLogin:
		http.Redirect(ctx.Res(), ctx.Req(), "/login?error", http.StatusFound)
		return nil
	case nil:
	default:
		return err
	}

	var (
		idStr string
		ok    bool
	)
	if idStr, ok = ctx.Params()["id"]; !ok {
		panic("no id")
	}
	id, err := strconv.ParseInt(idStr, 10, 32)
	if err != nil {
		panic(err)
	}
	p := post.ReadRaw(int(id))
	categories, err := category.Query()
	if err != nil {
		return err
	}

	layout := ThemeLayout{}
	layout.Content = ThemeBlock{theme.CP("post"), struct{ Post, Categories interface{} }{p, categories}}
	return ctx.Tpl(theme.CP("layout"), layout)
}
開發者ID:hjin-me,項目名稱:HJinBlog,代碼行數:34,代碼來源:post.go

示例3: DashBoard

func DashBoard(ctx banana.Context) error {
	err := Auth(ctx, PrivilegePostRead)
	switch err {
	case ErrNoPermit:
		http.Redirect(ctx.Res(), ctx.Req(), "/login?error&u=/cp/dashboard", http.StatusFound)
		return err
	case ErrNotLogin:
		http.Redirect(ctx.Res(), ctx.Req(), "/login?error&u=/cp/dashboard", http.StatusFound)
		return err
	case nil:
	default:
		return err
	}

	layout := ThemeLayout{}
	layout.Content = ThemeBlock{theme.CP("starter"), 1}
	return ctx.Tpl(theme.CP("layout"), layout)
}
開發者ID:hjin-me,項目名稱:HJinBlog,代碼行數:18,代碼來源:dashboard.go

示例4: Posts

func Posts(ctx banana.Context) error {

	err := Auth(ctx, PrivilegePostRead)
	switch err {
	case ErrNoPermit:
		return err
	case ErrNotLogin:
		http.Redirect(ctx.Res(), ctx.Req(), "/login?error&u=/cp/posts", http.StatusFound)
		return nil
	case nil:
	default:
		return err
	}

	ps := post.Query(0, 10)
	layout := ThemeLayout{}
	layout.Content = ThemeBlock{theme.CP("posts"), ps}
	return ctx.Tpl(theme.CP("layout"), layout)
}
開發者ID:hjin-me,項目名稱:HJinBlog,代碼行數:19,代碼來源:posts.go

示例5: Users

func Users(ctx banana.Context) error {
	err := Auth(ctx, PrivilegeUserRead)
	switch err {
	case ErrNoPermit:
		return err
	case ErrNotLogin:
		http.Redirect(ctx.Res(), ctx.Req(), "/login?error&u=/cp/users", http.StatusFound)
		return nil
	case nil:
	default:
		return err
	}

	users, err := user.Query(0, 10)
	if err != nil {
		return err
	}
	layout := ThemeLayout{}
	layout.Content = ThemeBlock{theme.CP("users"), struct{ List interface{} }{users}}
	return ctx.Tpl(theme.CP("layout"), layout)
}
開發者ID:hjin-me,項目名稱:HJinBlog,代碼行數:21,代碼來源:users.go

示例6: NewPost

func NewPost(ctx banana.Context) error {
	err := Auth(ctx, PrivilegePostRead)
	switch err {
	case ErrNoPermit:
		return err
	case ErrNotLogin:
		http.Redirect(ctx.Res(), ctx.Req(), "/login?error", http.StatusFound)
		return nil
	case nil:
	default:
		return err
	}

	categories, err := category.Query()
	if err != nil {
		return err
	}

	p := post.New()
	layout := ThemeLayout{}
	layout.Content = ThemeBlock{theme.CP("post"), struct{ Post, Categories interface{} }{p, categories}}
	return ctx.Tpl(theme.CP("layout"), layout)
}
開發者ID:hjin-me,項目名稱:HJinBlog,代碼行數:23,代碼來源:post.go

示例7: Login

func Login(ctx banana.Context) error {

	r := ctx.Req()
	username, pwd := r.FormValue("username"), r.FormValue("pwd")
	result, sign, err := user.Check(username, pwd)
	if err != nil {
		return err
	}
	if result {
		timeout := time.Now().Add(user.Expires)
		userCookie := &http.Cookie{}
		userCookie.Expires = timeout
		userCookie.Name = UID_COOKIE_NAME
		userCookie.Value = sign
		http.SetCookie(ctx.Res(), userCookie)
		http.Redirect(ctx.Res(), ctx.Req(), "/cp/dashboard", http.StatusFound)
	} else {
		http.Redirect(ctx.Res(), ctx.Req(), "/login?error", http.StatusFound)
	}

	return nil
}
開發者ID:hjin-me,項目名稱:HJinBlog,代碼行數:22,代碼來源:auth.go


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