Documentation ¶
Overview ¶
foked from https://github.com/martini-contrib/render/blob/master/render.go
Index ¶
- Constants
- Variables
- func Bind(obj interface{}, ifacePtr ...interface{}) martini.Handler
- func BindIgnErr(obj interface{}, ifacePtr ...interface{}) martini.Handler
- func ErrorHandler(errs base.BindingErrors, resp http.ResponseWriter)
- func Form(formStruct interface{}, ifacePtr ...interface{}) martini.Handler
- func InitContext() martini.Handler
- func Json(jsonStruct interface{}, ifacePtr ...interface{}) martini.Handler
- func Logger() martini.Handler
- func MultipartForm(formStruct interface{}, ifacePtr ...interface{}) martini.Handler
- func Renderer(options ...RenderOptions) martini.Handler
- func RepoAssignment(redirect bool, args ...bool) martini.Handler
- func Toggle(options *ToggleOptions) martini.Handler
- func Validate(obj interface{}) martini.Handler
- type Context
- func (ctx *Context) CsrfToken() string
- func (ctx *Context) CsrfTokenValid() bool
- func (ctx *Context) Debug(msg string, args ...interface{})
- func (ctx *Context) GetCookie(name string) string
- func (ctx *Context) GetSecureCookie(Secret, key string) (string, bool)
- func (ctx *Context) HTML(status int, name string, htmlOpt ...HTMLOptions)
- func (ctx *Context) Handle(status int, title string, err error)
- func (ctx *Context) HasError() bool
- func (ctx *Context) Query(name string) string
- func (ctx *Context) RenderWithErr(msg, tpl string, form auth.Form)
- func (ctx *Context) ServeContent(name string, r io.ReadSeeker, params ...interface{})
- func (ctx *Context) ServeFile(file string, names ...string)
- func (ctx *Context) SetCookie(name string, value string, others ...interface{})
- func (ctx *Context) SetSecureCookie(Secret, name, value string, others ...interface{})
- type Delims
- type Flash
- type HTMLOptions
- type Render
- func (r *Render) Error(status int, message ...string)
- func (r *Render) HTML(status int, name string, binding interface{}, htmlOpt ...HTMLOptions)
- func (r *Render) HTMLString(name string, binding interface{}, htmlOpt ...HTMLOptions) (string, error)
- func (r *Render) JSON(status int, v interface{})
- func (r *Render) JSONString(v interface{}) (string, error)
- func (r *Render) Redirect(location string, status ...int)
- func (r *Render) Template() *template.Template
- type RenderOptions
- type ToggleOptions
- type Validator
Constants ¶
const ( ContentType = "Content-Type" ContentLength = "Content-Length" ContentJSON = "application/json" ContentHTML = "text/html" ContentXHTML = "application/xhtml+xml" )
Variables ¶
var ( // Maximum amount of memory to use when parsing a multipart form. // Set this to whatever value you prefer; default is 10 MB. MaxMemory = int64(1024 * 1024 * 10) )
Functions ¶
func Bind ¶ added in v0.3.0
Bind accepts a copy of an empty struct and populates it with values from the request (if deserialization is successful). It wraps up the functionality of the Form and Json middleware according to the Content-Type of the request, and it guesses if no Content-Type is specified. Bind invokes the ErrorHandler middleware to bail out if errors occurred. If you want to perform your own error handling, use Form or Json middleware directly. An interface pointer can be added as a second argument in order to map the struct to a specific interface.
func BindIgnErr ¶ added in v0.3.0
BindIgnErr will do the exactly same thing as Bind but without any error handling, which user has freedom to deal with them. This allows user take advantages of validation.
func ErrorHandler ¶ added in v0.3.0
func ErrorHandler(errs base.BindingErrors, resp http.ResponseWriter)
ErrorHandler simply counts the number of errors in the context and, if more than 0, writes a 400 Bad Request response and a JSON payload describing the errors with the "Content-Type" set to "application/json". Middleware remaining on the stack will not even see the request if, by this point, there are any errors. This is a "default" handler, of sorts, and you are welcome to use your own instead. The Bind middleware invokes this automatically for convenience.
func Form ¶ added in v0.3.0
Form is middleware to deserialize form-urlencoded data from the request. It gets data from the form-urlencoded body, if present, or from the query string. It uses the http.Request.ParseForm() method to perform deserialization, then reflection is used to map each field into the struct with the proper type. Structs with primitive slice types (bool, float, int, string) can support deserialization of repeated form keys, for example: key=val1&key=val2&key=val3 An interface pointer can be added as a second argument in order to map the struct to a specific interface.
func InitContext ¶
InitContext initializes a classic context for a request.
func Json ¶ added in v0.3.0
Json is middleware to deserialize a JSON payload from the request into the struct that is passed in. The resulting struct is then validated, but no error handling is actually performed here. An interface pointer can be added as a second argument in order to map the struct to a specific interface.
func MultipartForm ¶ added in v0.3.0
func Renderer ¶
func Renderer(options ...RenderOptions) martini.Handler
func Toggle ¶
func Toggle(options *ToggleOptions) martini.Handler
Types ¶
type Context ¶
type Context struct { *Render Req *http.Request Res http.ResponseWriter Flash *Flash Session session.SessionStore Cache cache.Cache User *models.User IsSigned bool Repo struct { IsOwner bool IsWatching bool IsBranch bool IsTag bool IsCommit bool HasAccess bool Repository *models.Repository Owner *models.User Commit *git.Commit GitRepo *git.Repository BranchName string CommitId string RepoLink string CloneLink struct { SSH string HTTPS string Git string } Mirror *models.Mirror } // contains filtered or unexported fields }
Context represents context of a request.
func (*Context) CsrfTokenValid ¶
func (*Context) GetSecureCookie ¶
Get secure cookie from request by a given key.
func (*Context) HTML ¶
func (ctx *Context) HTML(status int, name string, htmlOpt ...HTMLOptions)
HTML calls render.HTML underlying but reduce one argument.
func (*Context) RenderWithErr ¶
RenderWithErr used for page has form validation but need to prompt error to users.
func (*Context) ServeContent ¶ added in v0.3.0
func (ctx *Context) ServeContent(name string, r io.ReadSeeker, params ...interface{})
func (*Context) SetSecureCookie ¶
Set Secure cookie for response.
type HTMLOptions ¶
type HTMLOptions struct {
Layout string
}
type Render ¶
type Render struct { http.ResponseWriter Data base.TmplData // contains filtered or unexported fields }
func (*Render) HTML ¶
func (r *Render) HTML(status int, name string, binding interface{}, htmlOpt ...HTMLOptions)
func (*Render) HTMLString ¶
func (r *Render) HTMLString(name string, binding interface{}, htmlOpt ...HTMLOptions) (string, error)