context

package
v0.0.0-...-c275005 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 29, 2024 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Contexter

func Contexter() macaron.Handler

Contexter initializes a classic context for a request.

func Toggle

func Toggle(options *ToggleOptions) macaron.Handler

Types

type Context

type Context struct {
	*macaron.Context
	Cache cache.Cache

	Flash   *session.Flash
	Session session.Store

	Link        string // Current request URL
	User        *db.User
	IsLogged    bool
	IsBasicAuth bool
	IsTokenAuth bool
	// contains filtered or unexported fields
}

Context represents context of a request.

func (*Context) Error

func (c *Context) Error(err error, msg string)

Error renders the 500 page.

func (*Context) Errorf

func (c *Context) Errorf(err error, format string, args ...interface{})

Errorf renders the 500 response with formatted message.

func (*Context) Fail

func (c *Context) Fail(code int64, msg string)

JSON Fail Message

func (*Context) FormErr

func (c *Context) FormErr(names ...string)

FormErr sets "Err_xxx" field in template data.

func (*Context) GetErrMsg

func (c *Context) GetErrMsg() string

func (*Context) HTML

func (c *Context) HTML(status int, name string)

HTML responses template with given status.

func (*Context) HasError

func (c *Context) HasError() bool

HasError returns true if error occurs in form validation.

func (*Context) HasValue

func (c *Context) HasValue(name string) bool

HasValue returns true if value of given name exists.

func (*Context) JSONSuccess

func (c *Context) JSONSuccess(data interface{})

JSONSuccess responses JSON with status http.StatusOK.

func (*Context) NotFound

func (c *Context) NotFound()

NotFound renders the 404 page.

func (*Context) NotFoundOrError

func (c *Context) NotFoundOrError(err error, msg string)

NotFoundOrError responses with 404 page for not found error and 500 page otherwise.

func (*Context) OK

func (c *Context) OK(msg string)

JSON Success Message

func (*Context) OKDATA

func (c *Context) OKDATA(msg string, data interface{})

func (*Context) PageIs

func (c *Context) PageIs(name string)

PageIs sets "PageIsxxx" field in template data.

func (*Context) RawTitle

func (c *Context) RawTitle(title string)

RawTitle sets the "Title" field in template data.

func (*Context) RedirectSubpath

func (c *Context) RedirectSubpath(location string, status ...int)

RedirectSubpath responses redirection with given location and status. It prepends setting.Server.Subpath to the location string.

func (*Context) RenderWithErr

func (c *Context) RenderWithErr(msg, tpl string, f interface{})

RenderWithErr used for page has form validation but need to prompt error to users.

func (*Context) Require

func (c *Context) Require(name string)

Require sets "Requirexxx" field in template data.

func (*Context) Success

func (c *Context) Success(name string)

Success responses template with status http.StatusOK.

func (*Context) Title

func (c *Context) Title(locale string)

Title localizes the "Title" field in template data.

type JsonMsg

type JsonMsg struct {
	Code int64       `json:"code"`
	Msg  string      `json:"msg"`
	Data interface{} `json:"data,omitempty"`
}

json api common data

type ToggleOptions

type ToggleOptions struct {
	SignInRequired  bool
	SignOutRequired bool
	AdminRequired   bool
	DisableCSRF     bool
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL