Documentation ¶
Index ¶
- Variables
- func NewCookie(name, value string, options *SessionOptions) *http.Cookie
- type API
- func (this *API) AddMiddleware(middlewareHandler MiddlewareHandler)
- func (this *API) AddResource(name string, resource interface{})
- func (this *API) AddRoute(method string, path string, actionHandler ActionHandler, ...)
- func (this *API) GetResource(name string) interface{}
- func (this *API) Run(host string) error
- func (this *API) ServeHTTP(resp http.ResponseWriter, req *http.Request)
- type Action
- func (this *Action) AddError(code int, text string)
- func (this *Action) AddParameter(name string, required bool, validators ...*validator.Validator)
- func (this *Action) GetErrors() ([]string, int)
- func (this *Action) GetInt64Param(key string) int64
- func (this *Action) GetIntParam(key string) int
- func (this *Action) GetParam(key string) string
- func (this *Action) GetURLInt64Param(key string) int64
- func (this *Action) GetURLIntParam(key string) int
- func (this *Action) GetURLParam(key string) string
- func (this *Action) HasErrors() bool
- func (this *Action) IsValid() bool
- func (this *Action) JSON(code int, obj interface{}, headers ...string)
- func (this *Action) Send(code int, text string, headers ...string)
- func (this *Action) SendByte(code int, data []byte, headers ...string)
- type ActionHandler
- type ActionInterface
- type Context
- func (c *Context) AddError(code int, text string)
- func (c *Context) Criticalln(args ...interface{})
- func (c *Context) Debugln(args ...interface{})
- func (c *Context) Errorln(args ...interface{})
- func (c *Context) FetchSession(name string) *Session
- func (c *Context) GetErrors() ([]string, int)
- func (c *Context) GetInt64Param(key string) int64
- func (c *Context) GetIntParam(key string) int
- func (c *Context) GetParam(key string) string
- func (c *Context) GetURLInt64Param(key string) int64
- func (c *Context) GetURLIntParam(key string) int
- func (c *Context) GetURLParam(key string) string
- func (c *Context) HasErrors() bool
- func (c *Context) JSON(code int, obj interface{}, headers ...string)
- func (c *Context) NewSession(name string) *Session
- func (c *Context) Next()
- func (c *Context) RemoteIP() string
- func (c *Context) Send(code int, text string, headers ...string)
- func (c *Context) SendByte(code int, data []byte, headers ...string)
- func (c *Context) Warningln(args ...interface{})
- type CookieStore
- type ErrorHandler
- type Form
- type FormElement
- func (e *FormElement) AddValidator(h FormValidatorHandler) *FormElement
- func (e *FormElement) Error() string
- func (e *FormElement) FormValue() string
- func (e *FormElement) Found() bool
- func (e *FormElement) Name() string
- func (e *FormElement) Required() bool
- func (e *FormElement) SetFormValue(v string)
- func (e *FormElement) SetRequired(r bool) *FormElement
- func (e *FormElement) SetValue(i interface{})
- func (e *FormElement) Validate(c *Context)
- func (e *FormElement) Value() interface{}
- type FormElementInterface
- type FormValidatorHandler
- func IsDate() FormValidatorHandler
- func IsEmail() FormValidatorHandler
- func IsEqual(refs ...string) FormValidatorHandler
- func IsFloat() FormValidatorHandler
- func IsInteger() FormValidatorHandler
- func IsUInteger() FormValidatorHandler
- func IsUUID() FormValidatorHandler
- func RegexpFormValidator(pattern string) FormValidatorHandler
- type M
- type MiddlewareHandler
- type MultiError
- type Parameter
- type Registry
- type Route
- type Router
- type Session
- func (s *Session) Changed() bool
- func (s *Session) Del(name string)
- func (s *Session) Destroy()
- func (s *Session) Get(name string) interface{}
- func (s *Session) Name() string
- func (s *Session) Save(r *http.Request, w http.ResponseWriter) error
- func (s *Session) Set(name string, value interface{})
- func (s *Session) SetMap(m map[string]interface{})
- type SessionOptions
- type Store
Constants ¶
This section is empty.
Variables ¶
var Hostname = ""
Functions ¶
Types ¶
type API ¶
type API struct { Middlewares []MiddlewareHandler Resources map[string]interface{} Error404Handler ErrorHandler Router Router Headers map[string]string }
func (*API) AddMiddleware ¶
func (this *API) AddMiddleware(middlewareHandler MiddlewareHandler)
func (*API) AddResource ¶
func (*API) AddRoute ¶
func (this *API) AddRoute(method string, path string, actionHandler ActionHandler, middlewares ...MiddlewareHandler)
func (*API) GetResource ¶
type Action ¶
func (*Action) AddParameter ¶
func (*Action) GetInt64Param ¶
func (*Action) GetIntParam ¶
func (*Action) GetURLInt64Param ¶
func (*Action) GetURLIntParam ¶
func (*Action) GetURLParam ¶
type ActionHandler ¶
type ActionHandler func(*Context) ActionInterface
type ActionInterface ¶
type Context ¶
type Context struct { Request *http.Request `json:"-"` Response http.ResponseWriter `json:"-"` API *API `json:"-"` Session *Session `json:"-"` ResponseStatusCode int `json:"-"` // Because we can't retrieve the status from http.ResponseWriter ResponseLength int `json:"-"` Errors map[string]string `json:"-"` ErrorCode int `json:"-"` // contains filtered or unexported fields }
func NewContext ¶
func (*Context) Criticalln ¶
func (c *Context) Criticalln(args ...interface{})
func (*Context) FetchSession ¶
Session may be nil
func (*Context) GetInt64Param ¶
func (*Context) GetIntParam ¶
func (*Context) GetURLInt64Param ¶
func (*Context) GetURLIntParam ¶
func (*Context) GetURLParam ¶
func (*Context) NewSession ¶
type CookieStore ¶
type CookieStore struct { Codecs []securecookie.Codec Options *SessionOptions // default configuration }
CookieStore stores sessions using secure cookies.
func NewCookieStore ¶
func NewCookieStore(keyPairs ...[]byte) *CookieStore
NewCookieStore returns a new CookieStore.
Keys are defined in pairs to allow key rotation, but the common case is to set a single authentication key and optionally an encryption key.
The first key in a pair is used for authentication and the second for encryption. The encryption key can be set to nil or omitted in the last pair, but the authentication key is required in all pairs.
It is recommended to use an authentication key with 32 or 64 bytes. The encryption key, if set, must be either 16, 24, or 32 bytes to select AES-128, AES-192, or AES-256 modes.
Use the convenience function securecookie.GenerateRandomKey() to create strong keys.
func (*CookieStore) Get ¶
Get returns a session for the given name after adding it to the registry.
It returns a new session if the sessions doesn't exist. Access IsNew on the session to check if it is an existing session or a new one.
It returns a new session and an error if the session exists but could not be decoded.
func (*CookieStore) MaxAge ¶
func (s *CookieStore) MaxAge(age int)
MaxAge sets the maximum age for the store and the underlying cookie implementation. Individual sessions can be deleted by setting Options.MaxAge = -1 for that session.
func (*CookieStore) New ¶
New returns a session for the given name without adding it to the registry.
The difference between New() and Get() is that calling New() twice will decode the session data twice, while Get() registers and reuses the same decoded session after the first call.
func (*CookieStore) Save ¶
func (s *CookieStore) Save(r *http.Request, w http.ResponseWriter, session *Session) error
Save adds a single session to the response.
type ErrorHandler ¶
type ErrorHandler func(*Context, interface{})
type Form ¶
type Form struct { Context *Context Elements map[string]FormElementInterface }
func NewForm ¶
func NewForm(c *Context, elems ...FormElementInterface) *Form
func (*Form) AddElement ¶
func (f *Form) AddElement(e FormElementInterface) *Form
func (*Form) Elem ¶
func (f *Form) Elem(name string) FormElementInterface
type FormElement ¶
type FormElement struct {
// contains filtered or unexported fields
}
func NewFormElement ¶
func NewFormElement(name, errStr string) *FormElement
func (*FormElement) AddValidator ¶
func (e *FormElement) AddValidator(h FormValidatorHandler) *FormElement
func (*FormElement) Error ¶
func (e *FormElement) Error() string
func (*FormElement) FormValue ¶
func (e *FormElement) FormValue() string
func (*FormElement) Found ¶
func (e *FormElement) Found() bool
func (*FormElement) Name ¶
func (e *FormElement) Name() string
func (*FormElement) Required ¶
func (e *FormElement) Required() bool
func (*FormElement) SetFormValue ¶
func (e *FormElement) SetFormValue(v string)
func (*FormElement) SetRequired ¶
func (e *FormElement) SetRequired(r bool) *FormElement
func (*FormElement) SetValue ¶
func (e *FormElement) SetValue(i interface{})
func (*FormElement) Validate ¶
func (e *FormElement) Validate(c *Context)
func (*FormElement) Value ¶
func (e *FormElement) Value() interface{}
type FormElementInterface ¶
type FormValidatorHandler ¶
type FormValidatorHandler func(*Context, FormElementInterface)
func IsDate ¶
func IsDate() FormValidatorHandler
func IsEmail ¶
func IsEmail() FormValidatorHandler
func IsEqual ¶
func IsEqual(refs ...string) FormValidatorHandler
func IsFloat ¶
func IsFloat() FormValidatorHandler
func IsInteger ¶
func IsInteger() FormValidatorHandler
func IsUInteger ¶
func IsUInteger() FormValidatorHandler
func IsUUID ¶
func IsUUID() FormValidatorHandler
func RegexpFormValidator ¶
func RegexpFormValidator(pattern string) FormValidatorHandler
type MiddlewareHandler ¶
type MiddlewareHandler func(*Context)
type MultiError ¶
type MultiError []error
MultiError stores multiple errors.
Borrowed from the App Engine SDK.
func (MultiError) Error ¶
func (m MultiError) Error() string
type Parameter ¶
func NewParameter ¶
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry stores sessions used during a request.
func GetRegistry ¶
GetRegistry returns a registry instance for the current request.
type Route ¶
type Route struct { Method string Path *regexp.Regexp ActionHandler ActionHandler Middlewares []MiddlewareHandler }
func NewRoute ¶
func NewRoute(method string, path string, actionHandler ActionHandler, middlewares ...MiddlewareHandler) *Route
type Session ¶
type Session struct { ID string Values map[string]interface{} Options *SessionOptions IsNew bool // contains filtered or unexported fields }
func NewSession ¶
func NewSession(name string, options *SessionOptions) *Session
type SessionOptions ¶
type SessionOptions struct { Path string Domain string // MaxAge=0 means no 'Max-Age' attribute specified. // MaxAge<0 means delete cookie now, equivalently 'Max-Age: 0'. // MaxAge>0 means Max-Age attribute present and given in seconds. MaxAge int Secure bool HttpOnly bool }
Options stores configuration for a session or session store.
Fields are a subset of http.Cookie fields.
type Store ¶
type Store interface { // Get should return a cached session. Get(r *http.Request, name string) (*Session, error) // New should create and return a new session. // // Note that New should never return a nil session, even in the case of // an error if using the Registry infrastructure to cache the session. New(r *http.Request, name string) (*Session, error) // Save should persist session to the underlying store implementation. Save(r *http.Request, w http.ResponseWriter, s *Session) error }
Store is an interface for custom session stores.
See CookieStore and FilesystemStore for examples.