Documentation
¶
Index ¶
- func Serve(config Config)
- type AutoTLSConfig
- type CORSOptions
- type Config
- type Context
- func (ctx *Context) AddHeader(key string, value string)
- func (ctx *Context) BasicAuthUser() acl.BasicAuthUser
- func (ctx *Context) End(status int, a ...string)
- func (ctx *Context) Error(err error)
- func (ctx *Context) File(filename string)
- func (ctx *Context) FormBool(key string, defaultValue bool) bool
- func (ctx *Context) FormFloat(key string, defaultValue float64) float64
- func (ctx *Context) FormInt(key string, defaultValue int64) int64
- func (ctx *Context) FormString(key string, defaultValue string) string
- func (ctx *Context) FormValues(key string) (a []string)
- func (ctx *Context) GetCookie(name string) (cookie *http.Cookie, err error)
- func (ctx *Context) Html(html string)
- func (ctx *Context) IfModified(modtime time.Time, then func())
- func (ctx *Context) IfNotMatch(etag string, then func())
- func (ctx *Context) Json(status int, v interface{})
- func (ctx *Context) MustUser() acl.User
- func (ctx *Context) Next()
- func (ctx *Context) Ok(text string)
- func (ctx *Context) ParseMultipartForm(maxMemoryBytes int64)
- func (ctx *Context) Redirect(status int, url string)
- func (ctx *Context) RemoteIP() string
- func (ctx *Context) RemoveCookie(cookie *http.Cookie)
- func (ctx *Context) Render(t string, data interface{})
- func (ctx *Context) Session() *Session
- func (ctx *Context) SetCookie(cookie *http.Cookie)
- func (ctx *Context) SetHeader(key string, value string)
- func (ctx *Context) User() acl.User
- func (ctx *Context) Write(p []byte) (n int, err error)
- func (ctx *Context) WriteString(s string) (n int, err error)
- type HTTPSConfig
- type Logger
- type REST
- func (rest *REST) Delete(path string, handles ...RESTHandle)
- func (rest *REST) Get(path string, handles ...RESTHandle)
- func (rest *REST) Handle(method string, path string, handles ...RESTHandle)
- func (rest *REST) Head(path string, handles ...RESTHandle)
- func (rest *REST) NotFound(handles ...RESTHandle)
- func (rest *REST) Options(path string, handles ...RESTHandle)
- func (rest *REST) Patch(path string, handles ...RESTHandle)
- func (rest *REST) Post(path string, handles ...RESTHandle)
- func (rest *REST) Put(path string, handles ...RESTHandle)
- func (rest *REST) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (rest *REST) SetTemplate(template *template.Template)
- func (rest *REST) Use(middlewares ...RESTHandle)
- type RESTHandle
- func ACL(getUser func(ctx *Context) acl.User) RESTHandle
- func BasicAuth(realm string, check func(name string, password string) (ok bool, err error)) RESTHandle
- func CORS(cors CORSOptions) RESTHandle
- func HTTPS() RESTHandle
- func Header(key string, value string) RESTHandle
- func Privileges(privileges ...string) RESTHandle
- func SessionManager(manager session.Manager) RESTHandle
- func Static(root string, fallbackPaths ...string) RESTHandle
- func Zip(path string) RESTHandle
- type Session
- type State
- type URL
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type AutoTLSConfig ¶ added in v0.4.0
type CORSOptions ¶ added in v0.5.0
type CORSOptions struct {
AllowOrigin string
AllowMethods []string
AllowHeaders []string
ExposeHeaders []string
AllowCredentials bool
MaxAge int // in seconds
}
func PublicCORS ¶
func PublicCORS() CORSOptions
type Context ¶
type Context struct {
W http.ResponseWriter
R *http.Request
URL *URL
State *State
// contains filtered or unexported fields
}
func (*Context) BasicAuthUser ¶ added in v0.5.0
func (ctx *Context) BasicAuthUser() acl.BasicAuthUser
func (*Context) FormValues ¶
func (*Context) IfModified ¶ added in v0.2.1
func (*Context) IfNotMatch ¶ added in v0.5.0
func (*Context) ParseMultipartForm ¶
func (*Context) RemoveCookie ¶
type HTTPSConfig ¶ added in v0.3.0
type HTTPSConfig struct {
Port uint16 `json:"port"`
CertFile string `json:"certFile"`
KeyFile string `json:"keyFile"`
AutoTLS AutoTLSConfig `json:"autotls"`
}
type Logger ¶ added in v0.5.0
type Logger interface {
Println(v ...interface{})
Printf(format string, v ...interface{})
}
type REST ¶ added in v0.4.0
type REST struct {
// Prefix to add base path at beginning of each route path
// For example if the Prefix equals "v2", the route path "/path" will be "/v2/path"
Prefix string
// Logger to log accesses
AccessLogger Logger
// Logger to log errors
Logger Logger
// If enabled, errors will be sent to the client.
// should be disable in production
SendError bool
// contains filtered or unexported fields
}
REST is a http.Handler which contains the router, middlewares and configuration settings
func (*REST) Delete ¶ added in v0.4.0
func (rest *REST) Delete(path string, handles ...RESTHandle)
Delete is a shortcut for router.Handle("DELETE", path, handles)
func (*REST) Get ¶ added in v0.4.0
func (rest *REST) Get(path string, handles ...RESTHandle)
Get is a shortcut for router.Handle("GET", path, handles)
func (*REST) Handle ¶ added in v0.4.0
func (rest *REST) Handle(method string, path string, handles ...RESTHandle)
Handle registers a new request handle with the given method and path.
func (*REST) Head ¶ added in v0.4.0
func (rest *REST) Head(path string, handles ...RESTHandle)
Head is a shortcut for router.Handle("HEAD", path, handles)
func (*REST) NotFound ¶ added in v0.5.0
func (rest *REST) NotFound(handles ...RESTHandle)
func (*REST) Options ¶ added in v0.4.0
func (rest *REST) Options(path string, handles ...RESTHandle)
Options is a shortcut for router.Handle("OPTIONS", path, handles)
func (*REST) Patch ¶ added in v0.4.0
func (rest *REST) Patch(path string, handles ...RESTHandle)
Patch is a shortcut for router.Handle("PATCH", path, handles)
func (*REST) Post ¶ added in v0.4.0
func (rest *REST) Post(path string, handles ...RESTHandle)
Post is a shortcut for router.Handle("POST", path, handles)
func (*REST) Put ¶ added in v0.4.0
func (rest *REST) Put(path string, handles ...RESTHandle)
Put is a shortcut for router.Handle("PUT", path, handles)
func (*REST) ServeHTTP ¶ added in v0.5.0
func (rest *REST) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP implements the http.Handler interface.
func (*REST) SetTemplate ¶ added in v0.5.3
SetTemplate sets template
func (*REST) Use ¶ added in v0.4.0
func (rest *REST) Use(middlewares ...RESTHandle)
Use injects middlewares to REST
type RESTHandle ¶ added in v0.4.0
type RESTHandle func(ctx *Context)
RESTHandle defines the handle of route or middleware of REST
func BasicAuth ¶ added in v0.4.0
func BasicAuth(realm string, check func(name string, password string) (ok bool, err error)) RESTHandle
BasicAuth returns a Basic HTTP Authorization middleware.
func CORS ¶
func CORS(cors CORSOptions) RESTHandle
func HTTPS ¶ added in v0.5.0
func HTTPS() RESTHandle
func Header ¶ added in v0.5.0
func Header(key string, value string) RESTHandle
func Privileges ¶ added in v0.5.0
func Privileges(privileges ...string) RESTHandle
func SessionManager ¶ added in v0.5.0
func SessionManager(manager session.Manager) RESTHandle
func Static ¶ added in v0.5.0
func Static(root string, fallbackPaths ...string) RESTHandle
func Zip ¶ added in v0.5.0
func Zip(path string) RESTHandle