Documentation
¶
Overview ¶
Package rex provides a simple & light-weight REST server in golang
Index ¶
- func Content(name string, motime time.Time, r io.ReadSeeker) interface{}
- func Error(message string, status int) interface{}
- func File(name string) interface{}
- func HTML(html string, status int) interface{}
- func Mutation(endpoint string, handles ...Handle)
- func Query(endpoint string, handles ...Handle)
- func Redirect(url string, status int) interface{}
- func Render(t Template, data interface{}) interface{}
- func RenderHTML(html string, data interface{}) interface{}
- func Serve(config ServerConfig) chan error
- func Start(port uint16) (err error)
- func StartAutoTLS(port uint16, hosts ...string) (err error)
- func StartTLS(port uint16, certFile string, keyFile string) (err error)
- func Static(root string, fallback string) interface{}
- func Use(middlewares ...Handle)
- type ACLUser
- type APIHandler
- type AutoTLSConfig
- type CORS
- type Context
- func (ctx *Context) ACLUser() ACLUser
- func (ctx *Context) AddHeader(key string, value string)
- func (ctx *Context) BasicAuthUser() (string, string)
- func (ctx *Context) Cookie(name string) (cookie *http.Cookie, err error)
- func (ctx *Context) DeleteHeader(key string)
- func (ctx *Context) EnableGzip()
- func (ctx *Context) RemoteIP() string
- func (ctx *Context) RemoveCookie(cookie *http.Cookie)
- func (ctx *Context) RemoveCookieByName(name string)
- func (ctx *Context) Session() *Session
- func (ctx *Context) SetACLUser(user ACLUser)
- func (ctx *Context) SetCookie(cookie *http.Cookie)
- func (ctx *Context) SetHeader(key string, value string)
- func (ctx *Context) SetValue(key string, value interface{})
- func (ctx *Context) Value(key string) (interface{}, bool)
- type Form
- func (form *Form) File(key string) (multipart.File, *multipart.FileHeader, error)
- func (form *Form) Float(key string) (float64, error)
- func (form *Form) Int(key string) (int64, error)
- func (form *Form) IsNil(key string) bool
- func (form *Form) Require(key string) string
- func (form *Form) RequireFloat(key string) float64
- func (form *Form) RequireInt(key string) int64
- func (form *Form) Value(key string) string
- type HTTPError
- type Handle
- func ACL(permissions ...string) Handle
- func AccessLogger(logger Logger) Handle
- func BasicAuth(auth func(name string, secret string) (ok bool, err error)) Handle
- func BasicAuthWithRealm(realm string, auth func(name string, secret string) (ok bool, err error)) Handle
- func Cors(cors CORS) Handle
- func ErrorLogger(logger Logger) Handle
- func Header(key string, value string) Handle
- func SIDStore(sidStore session.SIDStore) Handle
- func SessionPool(pool session.Pool) Handle
- type Logger
- type ServerConfig
- type Session
- type TLSConfig
- type Template
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Content ¶ added in v1.0.0
func Content(name string, motime time.Time, r io.ReadSeeker) interface{}
func Redirect ¶ added in v1.0.0
Redirect replies to the request with a redirect to url, which may be a path relative to the request path.
func RenderHTML ¶ added in v1.0.0
func RenderHTML(html string, data interface{}) interface{}
func StartAutoTLS ¶ added in v0.9.0
StartAutoTLS starts a REX server with autocert powered by Let's Encrypto SSL
Types ¶
type ACLUser ¶ added in v0.8.1
type ACLUser interface {
Permissions() []string
}
A ACLUser interface contains the Permissions method that returns the permission IDs
type APIHandler ¶ added in v1.0.0
type APIHandler struct {
// Prefix to add prefix for each api path, like "v2"
Prefix string
// contains filtered or unexported fields
}
APIHandler is a query/mutation style API http Handler
func (*APIHandler) Mutation ¶ added in v1.0.0
func (a *APIHandler) Mutation(endpoint string, handles ...Handle)
Mutation adds a mutation api
func (*APIHandler) Query ¶ added in v1.0.0
func (a *APIHandler) Query(endpoint string, handles ...Handle)
Query adds a query api
func (*APIHandler) ServeHTTP ¶ added in v1.0.0
func (a *APIHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP implements the http Handler.
func (*APIHandler) Use ¶ added in v1.0.0
func (a *APIHandler) Use(middlewares ...Handle)
Use appends middlewares to current APIS middleware stack.
type AutoTLSConfig ¶ added in v0.4.0
type AutoTLSConfig struct {
AcceptTOS bool `json:"acceptTOS"`
Hosts []string `json:"hosts"`
CacheDir string `json:"cacheDir"`
Cache autocert.Cache `json:"-"`
}
AutoTLSConfig contains options to support autocert by Let's Encrypto SSL.
type CORS ¶
type CORS struct {
AllowAllOrigins bool
AllowOrigins []string
AllowMethods []string
AllowHeaders []string
ExposeHeaders []string
AllowCredentials bool
MaxAge int // in seconds
}
CORS contains options to CORS.
type Context ¶
type Context struct {
W http.ResponseWriter
R *http.Request
Form *Form
// contains filtered or unexported fields
}
A Context to handle http requests.
func (*Context) AddHeader ¶ added in v0.1.5
AddHeader adds the key, value pair to the header of response writer.
func (*Context) BasicAuthUser ¶ added in v0.5.0
BasicAuthUser returns the BasicAuthed username and secret
func (*Context) DeleteHeader ¶ added in v0.14.0
DeleteHeader deletes the values associated with key.
func (*Context) EnableGzip ¶ added in v0.9.10
func (ctx *Context) EnableGzip()
EnableGzip enables the gzip compress
func (*Context) RemoveCookie ¶
RemoveCookie removes the cookie.
func (*Context) RemoveCookieByName ¶ added in v0.8.0
RemoveCookieByName removes the cookie by name.
func (*Context) SetACLUser ¶ added in v0.9.2
SetACLUser sets the acl user
func (*Context) SetHeader ¶ added in v0.1.5
SetHeader sets the header of response writer entries associated with key to the single element value.
type Form ¶ added in v0.11.0
A Form to handle http form
func (*Form) RequireFloat ¶ added in v0.11.0
RequireFloat requires a value as float
func (*Form) RequireInt ¶ added in v0.11.0
RequireInt requires a value as int
type Handle ¶ added in v0.8.0
type Handle func(ctx *Context) interface{}
Handle defines the API handle
func AccessLogger ¶ added in v0.13.2
AccessLogger returns a AccessLogger middleware to sets the access logger.
func BasicAuthWithRealm ¶ added in v0.8.0
func BasicAuthWithRealm(realm string, auth func(name string, secret string) (ok bool, err error)) Handle
BasicAuthWithRealm returns a Basic HTTP Authorization middleware with realm.
func ErrorLogger ¶ added in v0.13.2
ErrorLogger returns a ErrorLogger middleware to sets the error logger.
func SIDStore ¶ added in v0.6.2
SIDStore returns a SIDStore middleware to sets sid store for session.
func SessionPool ¶ added in v0.9.4
SessionPool returns a SessionPool middleware to set the session pool.
type Logger ¶ added in v0.5.0
type Logger interface {
Printf(format string, v ...interface{})
}
A Logger interface contains the Printf method.
type ServerConfig ¶ added in v0.12.5
type ServerConfig struct {
Host string `json:"host"`
Port uint16 `json:"port"`
TLS TLSConfig `json:"tls"`
ReadTimeout uint32 `json:"readTimeout"`
WriteTimeout uint32 `json:"writeTimeout"`
MaxHeaderBytes uint32 `json:"maxHeaderBytes"`
}
ServerConfig contains options to run the REX server.
type Session ¶ added in v0.5.1
Session handles sessions for Context