Documentation ¶
Index ¶
- Variables
- func AddGlobalInterceptors(interceptors ...Interceptor)
- func AutoIssueTLSCertificates(tlsCfg *config.TLSConfig, cfg *tls.Config)
- func BasicAuth(h httprouter.Handle, requiredUser, requiredPassword string) httprouter.Handle
- func DestroySession(w http.ResponseWriter, r *http.Request) bool
- func EnableAuth(enable bool)
- func GetAppSetting(key string) interface{}
- func GetAppSettings() util.MapStr
- func GetClientTLSConfig(tlsConfig *config.TLSConfig) (*tls.Config, error)
- func GetFlash(w http.ResponseWriter, r *http.Request) (bool, []interface{})
- func GetServerTLSConfig(tlsCfg *config.TLSConfig) (*tls.Config, error)
- func GetSession(r *http.Request, key string) (bool, interface{})
- func GetSessionStore(r *http.Request, key string) (*sessions.Session, error)
- func HandleAPIFunc(pattern string, handler func(http.ResponseWriter, *http.Request))
- func HandleAPIMethod(method Method, pattern string, ...)
- func HandleUI(pattern string, handler http.Handler)
- func HandleUIFunc(pattern string, handler func(http.ResponseWriter, *http.Request))
- func HandleUIMethod(method Method, pattern string, ...)
- func HandleWebSocketCommand(command string, usage string, ...)
- func IsAuthEnable() bool
- func NewHTTPClient(clientCfg *config.HTTPClientConfig) (*http.Client, error)
- func RecoveryHandler(opts ...RecoveryOption) func(h http.Handler) http.Handler
- func RegisterAPIFilter(f filter.Filter)
- func RegisterAppSetting(key string, v interface{})
- func SetFlash(w http.ResponseWriter, r *http.Request, msg string) bool
- func SetNotFoundHandler(handler func(rw http.ResponseWriter, r *http.Request))
- func SetSession(w http.ResponseWriter, r *http.Request, key string, value interface{}) bool
- func SimpleGetTLSConfig(tlsConfig *config.TLSConfig) *tls.Config
- func StartAPI()
- func StartWeb(cfg config.WebAppConfig)
- func StopWeb(cfg config.WebAppConfig)
- type AppSettings
- type BasicAuthFilter
- type BasicTokenTransport
- type FoundResp
- type Handler
- func (handler Handler) DecodeJSON(r *http.Request, o interface{}) error
- func (handler Handler) EncodeJSON(v interface{}) (b []byte, err error)
- func (handler Handler) Error(w http.ResponseWriter, err error)
- func (handler Handler) Error400(w http.ResponseWriter, msg string)
- func (handler Handler) Error404(w http.ResponseWriter)
- func (handler Handler) Error500(w http.ResponseWriter, msg string)
- func (handler Handler) ErrorInternalServer(w http.ResponseWriter, msg string)
- func (handler Handler) Flush(w http.ResponseWriter)
- func (handler Handler) Get(req *http.Request, key string, defaultValue string) string
- func (handler Handler) GetHeader(req *http.Request, key string, defaultValue string) string
- func (handler Handler) GetIntOrDefault(r *http.Request, key string, defaultValue int) int
- func (handler Handler) GetJSON(r *http.Request) (*jsonq.JsonQuery, error)
- func (handler Handler) GetParameter(r *http.Request, key string) string
- func (handler Handler) GetParameterOrDefault(r *http.Request, key string, defaultValue string) string
- func (handler Handler) GetRawBody(r *http.Request) ([]byte, error)
- func (handler Handler) MustGetParameter(w http.ResponseWriter, r *http.Request, key string) string
- func (handler Handler) Redirect(w http.ResponseWriter, r *http.Request, url string)
- func (handler Handler) Write(w http.ResponseWriter, b []byte) (int, error)
- func (handler Handler) WriteAckJSON(w http.ResponseWriter, ack bool, status int, obj map[string]interface{}) error
- func (handler Handler) WriteAckOKJSON(w http.ResponseWriter) error
- func (handler Handler) WriteCreatedOKJSON(w http.ResponseWriter, id interface{}) error
- func (handler Handler) WriteDeletedOKJSON(w http.ResponseWriter, id interface{}) error
- func (handler Handler) WriteError(w http.ResponseWriter, errMessage string, statusCode int) error
- func (handler Handler) WriteGetMissingJSON(w http.ResponseWriter, id string) error
- func (handler Handler) WriteGetOKJSON(w http.ResponseWriter, id, obj interface{}) error
- func (handler Handler) WriteHeader(w http.ResponseWriter, code int)
- func (handler Handler) WriteJSON(w http.ResponseWriter, v interface{}, statusCode int) error
- func (handler Handler) WriteJSONHeader(w http.ResponseWriter)
- func (handler Handler) WriteJSONListResult(w http.ResponseWriter, total int64, v interface{}, statusCode int) error
- func (handler Handler) WriteOKJSON(w http.ResponseWriter, v interface{}) error
- func (handler Handler) WriteTextHeader(w http.ResponseWriter)
- func (handler Handler) WriteUpdatedOKJSON(w http.ResponseWriter, id interface{}) error
- type Interceptor
- type InterceptorHandler
- type Method
- type RecoveryOption
- type Response
- type Result
Constants ¶
This section is empty.
Variables ¶
var APIs = map[string]util.KV{}
var DefaultAPI = Handler{}
Functions ¶
func AddGlobalInterceptors ¶
func AddGlobalInterceptors(interceptors ...Interceptor)
func BasicAuth ¶
func BasicAuth(h httprouter.Handle, requiredUser, requiredPassword string) httprouter.Handle
BasicAuth register api with basic auth
func DestroySession ¶
func DestroySession(w http.ResponseWriter, r *http.Request) bool
DestroySession remove session by creating a new empty session
func EnableAuth ¶
func EnableAuth(enable bool)
func GetAppSetting ¶
func GetAppSetting(key string) interface{}
func GetAppSettings ¶
func GetFlash ¶
func GetFlash(w http.ResponseWriter, r *http.Request) (bool, []interface{})
GetFlash get flash value
func GetSession ¶
GetSession return session by session key
func HandleAPIFunc ¶
func HandleAPIFunc(pattern string, handler func(http.ResponseWriter, *http.Request))
HandleAPIFunc register api handler to specify pattern
func HandleAPIMethod ¶
func HandleAPIMethod(method Method, pattern string, handler func(w http.ResponseWriter, req *http.Request, ps httprouter.Params))
HandleAPIMethod register api handler
func HandleUIFunc ¶
func HandleUIFunc(pattern string, handler func(http.ResponseWriter, *http.Request))
HandleUIFunc register ui request handler
func HandleUIMethod ¶
func HandleUIMethod(method Method, pattern string, handler func(w http.ResponseWriter, req *http.Request, ps httprouter.Params))
HandleUIMethod register ui request handler
func HandleWebSocketCommand ¶
func HandleWebSocketCommand(command string, usage string, handler func(c *websocket.WebsocketConnection, array []string))
HandleWebSocketCommand register websocket command handler
func IsAuthEnable ¶
func IsAuthEnable() bool
func NewHTTPClient ¶
func NewHTTPClient(clientCfg *config.HTTPClientConfig) (*http.Client, error)
func RecoveryHandler ¶
func RecoveryHandler(opts ...RecoveryOption) func(h http.Handler) http.Handler
RecoveryHandler is HTTP middleware that recovers from a panic, logs the panic, writes http.StatusInternalServerError, and continues to the next handler.
func RegisterAPIFilter ¶
func RegisterAppSetting ¶
func RegisterAppSetting(key string, v interface{})
func SetNotFoundHandler ¶
func SetNotFoundHandler(handler func(rw http.ResponseWriter, r *http.Request))
func SetSession ¶
SetSession set session by session key and session value
func StartWeb ¶
func StartWeb(cfg config.WebAppConfig)
func StopWeb ¶
func StopWeb(cfg config.WebAppConfig)
Types ¶
type AppSettings ¶
func (*AppSettings) Add ¶
func (settings *AppSettings) Add(key string, v interface{})
func (*AppSettings) Get ¶
func (settings *AppSettings) Get(key string) interface{}
func (*AppSettings) GetSettingsMap ¶
func (settings *AppSettings) GetSettingsMap() util.MapStr
type BasicAuthFilter ¶
func (*BasicAuthFilter) FilterHttpHandlerFunc ¶
func (filter *BasicAuthFilter) FilterHttpHandlerFunc(pattern string, handler func(http.ResponseWriter, *http.Request)) func(http.ResponseWriter, *http.Request)
func (*BasicAuthFilter) FilterHttpRouter ¶
func (filter *BasicAuthFilter) FilterHttpRouter(pattern string, h httprouter.Handle) httprouter.Handle
type BasicTokenTransport ¶
type BasicTokenTransport struct { Token string Transport http.RoundTripper }
func (*BasicTokenTransport) Client ¶
func (t *BasicTokenTransport) Client() *http.Client
type FoundResp ¶
type FoundResp struct { Found bool `json:"found"` Id string `json:"_id,omitempty"` Source interface{} `json:"_source,omitempty"` }
func FoundResponse ¶
func NotFoundResponse ¶
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
Handler is the object of http handler
func (Handler) EncodeJSON ¶
EncodeJSON encode the object to json string
func (Handler) Error ¶
func (handler Handler) Error(w http.ResponseWriter, err error)
Error output custom error
func (Handler) Error404 ¶
func (handler Handler) Error404(w http.ResponseWriter)
Error404 output 404 response
func (Handler) Error500 ¶
func (handler Handler) Error500(w http.ResponseWriter, msg string)
Error500 output 500 response
func (Handler) ErrorInternalServer ¶
func (handler Handler) ErrorInternalServer(w http.ResponseWriter, msg string)
func (Handler) Flush ¶
func (handler Handler) Flush(w http.ResponseWriter)
Flush flush response message
func (Handler) GetIntOrDefault ¶
GetIntOrDefault return parameter or default, data type is int
func (Handler) GetParameter ¶
GetParameter return query parameter with argument name
func (Handler) GetParameterOrDefault ¶
func (handler Handler) GetParameterOrDefault(r *http.Request, key string, defaultValue string) string
GetParameterOrDefault return query parameter or return default value
func (Handler) GetRawBody ¶
GetRawBody return raw http request body
func (Handler) MustGetParameter ¶
func (Handler) WriteAckJSON ¶
func (Handler) WriteAckOKJSON ¶
func (handler Handler) WriteAckOKJSON(w http.ResponseWriter) error
func (Handler) WriteCreatedOKJSON ¶
func (handler Handler) WriteCreatedOKJSON(w http.ResponseWriter, id interface{}) error
func (Handler) WriteDeletedOKJSON ¶
func (handler Handler) WriteDeletedOKJSON(w http.ResponseWriter, id interface{}) error
func (Handler) WriteError ¶
func (Handler) WriteGetMissingJSON ¶
func (handler Handler) WriteGetMissingJSON(w http.ResponseWriter, id string) error
func (Handler) WriteGetOKJSON ¶
func (handler Handler) WriteGetOKJSON(w http.ResponseWriter, id, obj interface{}) error
func (Handler) WriteHeader ¶
func (handler Handler) WriteHeader(w http.ResponseWriter, code int)
WriteHeader write status code to http header
func (Handler) WriteJSON ¶
func (handler Handler) WriteJSON(w http.ResponseWriter, v interface{}, statusCode int) error
func (Handler) WriteJSONHeader ¶
func (handler Handler) WriteJSONHeader(w http.ResponseWriter)
WriteJSONHeader will write standard json header
func (Handler) WriteJSONListResult ¶
func (handler Handler) WriteJSONListResult(w http.ResponseWriter, total int64, v interface{}, statusCode int) error
WriteJSONListResult output result list to json format
func (Handler) WriteOKJSON ¶
func (handler Handler) WriteOKJSON(w http.ResponseWriter, v interface{}) error
func (Handler) WriteTextHeader ¶
func (handler Handler) WriteTextHeader(w http.ResponseWriter)
func (Handler) WriteUpdatedOKJSON ¶
func (handler Handler) WriteUpdatedOKJSON(w http.ResponseWriter, id interface{}) error
type Interceptor ¶
type InterceptorHandler ¶
type InterceptorHandler struct {
// contains filtered or unexported fields
}
func NewInterceptorHandler ¶
func NewInterceptorHandler() *InterceptorHandler
func (*InterceptorHandler) AddInterceptors ¶
func (i *InterceptorHandler) AddInterceptors(interceptors ...Interceptor)
type RecoveryOption ¶
RecoveryOption provides a functional approach to define configuration for a handler; such as setting the logging whether or not to print stack traces on panic.
func PrintRecoveryStack ¶
func PrintRecoveryStack(print bool) RecoveryOption
PrintRecoveryStack is a functional option to enable or disable printing stack traces on panic.
type Response ¶
type Response struct { Total int64 `json:"total,omitempty"` Hit interface{} `json:"hit,omitempty"` Id string `json:"_id,omitempty"` Result string `json:"result,omitempty"` }