middleware

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Jun 1, 2014 License: BSD-3-Clause Imports: 28 Imported by: 0

Documentation

Overview

foked from https://github.com/martini-contrib/render/blob/master/render.go

Index

Constants

View Source
const (
	ContentType   = "Content-Type"
	ContentLength = "Content-Length"
	ContentJSON   = "application/json"
	ContentHTML   = "text/html"
	ContentXHTML  = "application/xhtml+xml"
)

Variables

This section is empty.

Functions

func InitContext

func InitContext() martini.Handler

InitContext initializes a classic context for a request.

func Logger

func Logger() martini.Handler

func Renderer

func Renderer(options ...RenderOptions) martini.Handler

func RepoAssignment

func RepoAssignment(redirect bool, args ...bool) martini.Handler

func RequireOwner added in v0.4.0

func RequireOwner() 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) CsrfToken

func (ctx *Context) CsrfToken() string

func (*Context) CsrfTokenValid

func (ctx *Context) CsrfTokenValid() bool

func (*Context) Debug

func (ctx *Context) Debug(msg string, args ...interface{})

func (*Context) GetCookie

func (ctx *Context) GetCookie(name string) string

func (*Context) GetErrMsg added in v0.4.0

func (ctx *Context) GetErrMsg() string

func (*Context) GetSecureCookie

func (ctx *Context) GetSecureCookie(Secret, key string) (string, bool)

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

func (ctx *Context) Handle(status int, title string, err error)

Handle handles and logs error by given status.

func (*Context) HasApiError added in v0.4.0

func (ctx *Context) HasApiError() bool

HasError returns true if error occurs in form validation.

func (*Context) HasError

func (ctx *Context) HasError() bool

HasError returns true if error occurs in form validation.

func (*Context) Query

func (ctx *Context) Query(name string) string

Query querys form parameter.

func (*Context) RenderWithErr

func (ctx *Context) RenderWithErr(msg, tpl string, form auth.Form)

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) ServeFile added in v0.3.0

func (ctx *Context) ServeFile(file string, names ...string)

func (*Context) SetCookie

func (ctx *Context) SetCookie(name string, value string, others ...interface{})

func (*Context) SetSecureCookie

func (ctx *Context) SetSecureCookie(Secret, name, value string, others ...interface{})

Set Secure cookie for response.

type Delims

type Delims struct {
	Left  string
	Right string
}

type Flash added in v0.3.0

type Flash struct {
	url.Values
	ErrorMsg, SuccessMsg string
}

func (*Flash) Error added in v0.3.0

func (f *Flash) Error(msg string)

func (*Flash) Success added in v0.3.0

func (f *Flash) Success(msg string)

type HTMLOptions

type HTMLOptions struct {
	Layout string
}

type Render

type Render struct {
	http.ResponseWriter

	Data base.TmplData
	// contains filtered or unexported fields
}

func (*Render) Error

func (r *Render) Error(status int, message ...string)

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)

func (*Render) JSON

func (r *Render) JSON(status int, v interface{})

func (*Render) JSONString

func (r *Render) JSONString(v interface{}) (string, error)

func (*Render) Redirect

func (r *Render) Redirect(location string, status ...int)

func (*Render) Template

func (r *Render) Template() *template.Template

type RenderOptions

type RenderOptions struct {
	Directory       string
	Layout          string
	Extensions      []string
	Funcs           []template.FuncMap
	Delims          Delims
	Charset         string
	IndentJSON      bool
	HTMLContentType string
}

type ToggleOptions

type ToggleOptions struct {
	SignInRequire  bool
	SignOutRequire bool
	AdminRequire   bool
	DisableCsrf    bool
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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