Documentation
¶
Overview ¶
Package rex provides provides a REST server that can debug, build, and host a SPA(single page appliaction).
APIService ¶
APIService provides a REST API service with user privileges.
var apis = &rex.APIService {
Prefix: 'v2',
}
apis.Options('*', rex.PublicCORS)
apis.Head('endpoint', func(ctx *rex.Context) {}, 'privilegeId')
apis.Get('endpoint', func(ctx *rex.Context) {}, 'privilegeId')
apis.POST('endpoint', func(ctx *rex.Context) {}, 'privilegeId')
apis.Put('endpoint', func(ctx *rex.Context) {}, 'privilegeId')
apis.Patch('endpoint', func(ctx *rex.Context) {}, 'privilegeId')
apis.Delete('endpoint', func(ctx *rex.Context) {}, 'privilegeId')
apis.Use(func(ctx *rex.Context, next func()) {} )
Index ¶
- func Serve(config Config)
- type APIHandle
- type APIService
- func (s *APIService) Delete(endpoint string, handle APIHandle, privilegeIds ...string)
- func (s *APIService) Get(endpoint string, handle APIHandle, privilegeIds ...string)
- func (s *APIService) Head(endpoint string, handle APIHandle, privilegeIds ...string)
- func (s *APIService) Options(endpoint string, cors *CORS)
- func (s *APIService) Patch(endpoint string, handle APIHandle, privilegeIds ...string)
- func (s *APIService) Post(endpoint string, handle APIHandle, privilegeIds ...string)
- func (s *APIService) Put(endpoint string, handle APIHandle, privilegeIds ...string)
- func (s *APIService) Use(middleware MiddlewareHandle)
- type App
- type AppBuildRecord
- type AppMux
- type CORS
- type Config
- type Context
- func (ctx *Context) Authenticate(realm string, ...) (ok bool, err error)
- func (ctx *Context) Cookie(name string) (cookie *http.Cookie, err error)
- func (ctx *Context) End(status int, a ...string)
- func (ctx *Context) Error(err error)
- func (ctx *Context) FormBool(key string) (b bool)
- func (ctx *Context) FormInt(key string) (i int, err error)
- func (ctx *Context) FormJSON(key string) (value map[string]interface{}, err error)
- func (ctx *Context) FormNumber(key string) (n float64, err error)
- func (ctx *Context) FormString(key string) (value string)
- func (ctx *Context) FormValues(key string) (values []string)
- func (ctx *Context) Get(key string) (v interface{}, ok bool)
- func (ctx *Context) ParseMultipartForm(maxMemoryBytes int64)
- func (ctx *Context) Redirect(url string, code int)
- func (ctx *Context) RemoteIP() (ip string)
- func (ctx *Context) RemoveCookie(cookie *http.Cookie)
- func (ctx *Context) Session() (sess session.Session)
- func (ctx *Context) Set(key string, v interface{})
- func (ctx *Context) SetCookie(cookie *http.Cookie)
- func (ctx *Context) SetUser(user acl.User)
- func (ctx *Context) User() acl.User
- func (ctx *Context) Write(p []byte) (n int, err error)
- func (ctx *Context) WriteJSON(data interface{}) (n int, err error)
- func (ctx *Context) WriteStatusJSON(status int, data interface{}) (n int, err error)
- func (ctx *Context) WriteString(s string) (n int, err error)
- type MiddlewareHandle
- type Mux
- type ResponseWriter
- type URL
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type APIService ¶
type APIService struct {
Prefix string
// contains filtered or unexported fields
}
func NewAPIService ¶
func NewAPIService() *APIService
func NewAPIServiceWithPrefix ¶
func NewAPIServiceWithPrefix(prefix string) *APIService
func (*APIService) Delete ¶
func (s *APIService) Delete(endpoint string, handle APIHandle, privilegeIds ...string)
func (*APIService) Get ¶
func (s *APIService) Get(endpoint string, handle APIHandle, privilegeIds ...string)
func (*APIService) Head ¶
func (s *APIService) Head(endpoint string, handle APIHandle, privilegeIds ...string)
func (*APIService) Options ¶
func (s *APIService) Options(endpoint string, cors *CORS)
func (*APIService) Patch ¶
func (s *APIService) Patch(endpoint string, handle APIHandle, privilegeIds ...string)
func (*APIService) Post ¶
func (s *APIService) Post(endpoint string, handle APIHandle, privilegeIds ...string)
func (*APIService) Put ¶
func (s *APIService) Put(endpoint string, handle APIHandle, privilegeIds ...string)
func (*APIService) Use ¶
func (s *APIService) Use(middleware MiddlewareHandle)
type App ¶
type App struct {
// contains filtered or unexported fields
}
func (*App) Build ¶
func (app *App) Build() *AppBuildRecord
func (*App) BuildRecords ¶
func (app *App) BuildRecords() []*AppBuildRecord
type AppBuildRecord ¶
type CORS ¶
type CORS struct {
Origin string
Methods []string
Headers []string
Credentials bool
MaxAge int // seconds
}
func PublicCORS ¶
func PublicCORS() *CORS
type Config ¶
type Config struct {
Port uint16 `json:"port"`
AppDir string `json:"appDir"`
ServerName string `json:"serverName"`
CustomHTTPHeaders map[string]string `json:"customHTTPHeaders"`
SessionCookieName string `json:"sessionCookieName"`
HostRedirectRule string `json:"hostRedirectRule"`
ReadTimeout uint32 `json:"readTimeout"`
WriteTimeout uint32 `json:"writeTimeout"`
MaxHeaderBytes uint32 `json:"maxHeaderBytes"`
Debug bool `json:"debug"`
NotFoundHandler http.Handler `json:"-"`
ErrorLogger *log.Logger `json:"-"`
AccessLogger *log.Logger `json:"-"`
}
type Context ¶
type Context struct {
App *App
ResponseWriter http.ResponseWriter
Request *http.Request
URL *URL
// contains filtered or unexported fields
}
func (*Context) Authenticate ¶
func (*Context) FormString ¶
func (*Context) FormValues ¶
func (*Context) ParseMultipartForm ¶
func (*Context) RemoveCookie ¶
func (*Context) WriteStatusJSON ¶
type MiddlewareHandle ¶
type MiddlewareHandle func(*Context, func())
type Mux ¶
type Mux struct {
App *App
Debug bool
ServerName string
CustomHTTPHeaders map[string]string
SessionCookieName string
HostRedirectRule string
NotFoundHandler http.Handler
SessionManager session.Manager
AccessLogger *log.Logger
Logger *log.Logger
// contains filtered or unexported fields
}
func (*Mux) RegisterAPIService ¶
func (mux *Mux) RegisterAPIService(apis *APIService)
type ResponseWriter ¶
type ResponseWriter struct {
// contains filtered or unexported fields
}
func (*ResponseWriter) Header ¶
func (w *ResponseWriter) Header() http.Header
func (*ResponseWriter) Status ¶
func (w *ResponseWriter) Status() (status int, writedBytes int)
func (*ResponseWriter) WriteHeader ¶
func (w *ResponseWriter) WriteHeader(status int)
Click to show internal directories.
Click to hide internal directories.