context

package
v0.0.0-...-4c4c41a Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2025 License: MIT Imports: 13 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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
	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(msg string)

Fail returns a failure JSON response

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

func (c *Context) HTMLString(name, content string)

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

Ok returns a success JSON response

func (*Context) PageIs

func (c *Context) PageIs(name string)

PageIs sets "PageIsxxx" field in template data.

func (*Context) PlainText

func (c *Context) PlainText(status int, name []byte)

TEXT responses template with given status.

func (*Context) RawData

func (c *Context) RawData(status int, v []byte)

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

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

RenderJSON renders JSON response with status http.StatusOK

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

func (c *Context) ReturnJSON(code int64, msg string, data interface{})

ReturnJSON returns a standard JSON API response

func (*Context) ReturnLayuiJSON

func (c *Context) ReturnLayuiJSON(code int64, msg string, count int, data interface{})

ReturnLayuiJSON returns a Layui table JSON response

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 JSONData

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

JSONData represents the standard JSON API response structure

type LayuiData

type LayuiData struct {
	Code  int64       `json:"code"`
	Count int         `json:"count"`
	Msg   string      `json:"msg"`
	Data  interface{} `json:"data,omitempty"`
}

LayuiData represents the Layui table JSON response structure

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