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 BypassCORSCheck(next http.Handler) http.Handler
- func DestroySession(w http.ResponseWriter, r *http.Request) bool
- func EncodeJSON(v interface{}) (b []byte, err error)
- func GetAppSetting(key string) interface{}
- func GetAppSettings() util.MapStr
- func GetClientTLSConfig(tlsConfig *config.TLSConfig) (*tls.Config, error)
- func GetFastHttpClient(name string) *fasthttp.Client
- func GetFlash(w http.ResponseWriter, r *http.Request) (bool, []interface{})
- func GetHttpClient(name string) *http.Client
- 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 HandleUIMethod(method Method, pattern string, ...)
- func HandleWebSocketCommand(command string, usage string, ...)
- func IsAuthEnable() bool
- func NewHTTPClient(clientCfg *config.HTTPClientConfig) (*http.Client, error)
- func PrepareErrorJson(errMessage string, statusCode int) util.MapStr
- func RecoveryHandler(opts ...RecoveryOption) func(h http.Handler) http.Handler
- func RegisterAPIFilter(f filter.Filter)
- func RegisterAppSetting(key string, v interface{})
- func RegisterUIFilter(filter UIFilters)
- 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)
- func UpdateProxyEnvironment(cfg *config.ProxyConfig)
- func WriteJSON(w http.ResponseWriter, v interface{}, statusCode int) error
- type AppSettings
- type BasicAuthFilter
- type BasicTokenTransport
- type FoundResp
- type Handler
- func (handler Handler) DecodeJSON(r *http.Request, o interface{}) 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) GetBoolOrDefault(r *http.Request, key string, defaultValue bool) bool
- 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) WriteAckWithMessage(w http.ResponseWriter, ack bool, status int, msg string) error
- func (handler Handler) WriteBytes(w http.ResponseWriter, b []byte, statusCode int) 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) WriteErrorObject(w http.ResponseWriter, err interface{}, status int)
- 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) WriteJSONBytes(w http.ResponseWriter, b []byte, 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) WriteJavascriptHeader(w http.ResponseWriter)
- 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 HandlerOptions
- type Interceptor
- type InterceptorHandler
- type Method
- type Option
- func Action(action string) Option
- func AllowPublicAccess() Option
- func Feature(feature string) Option
- func Label(label string, v interface{}) Option
- func Name(name string) Option
- func OptionLogin() Option
- func RequireLogin() Option
- func RequirePermission(permissions ...string) Option
- func Resource(source string) Option
- type OptionRegistry
- type RecoveryOption
- type RegisteredAPIHandler
- type Response
- type Result
- type UIFilters
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 BypassCORSCheck ¶ added in v1.1.5
BypassCORSCheck wraps an HTTP handler to allow all origins
func DestroySession ¶
func DestroySession(w http.ResponseWriter, r *http.Request) bool
DestroySession remove session by creating a new empty session
func EncodeJSON ¶ added in v1.1.4
EncodeJSON encode the object to json string
func GetAppSetting ¶
func GetAppSetting(key string) interface{}
func GetAppSettings ¶
func GetFastHttpClient ¶ added in v1.1.0
func GetFlash ¶
func GetFlash(w http.ResponseWriter, r *http.Request) (bool, []interface{})
GetFlash get flash value
func GetHttpClient ¶ added in v1.1.0
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 HandleUIMethod ¶
func HandleUIMethod(method Method, pattern string, handler func(w http.ResponseWriter, req *http.Request, ps httprouter.Params), options ...Option)
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 NewHTTPClient ¶
func NewHTTPClient(clientCfg *config.HTTPClientConfig) (*http.Client, error)
func PrepareErrorJson ¶ added in v1.1.3
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 RegisterUIFilter ¶ added in v1.1.4
func RegisterUIFilter(filter UIFilters)
RegisterUIFilter adds a filter to the chain (typically called during initialization)
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)
func UpdateProxyEnvironment ¶ added in v1.1.0
func UpdateProxyEnvironment(cfg *config.ProxyConfig)
UpdateProxyEnvironment sets the system environment variables based on the ProxyConfig. It will override any existing environment variables with the new values provided in the config.
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) 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) GetBoolOrDefault ¶ added in v1.1.2
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) WriteAckWithMessage ¶ added in v1.1.5
func (Handler) WriteBytes ¶ added in v1.1.0
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) WriteErrorObject ¶ added in v1.1.4
func (handler Handler) WriteErrorObject(w http.ResponseWriter, err interface{}, status int)
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) WriteJSONBytes ¶ added in v1.1.5
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) WriteJavascriptHeader ¶ added in v1.1.5
func (handler Handler) WriteJavascriptHeader(w http.ResponseWriter)
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 HandlerOptions ¶ added in v1.1.4
type HandlerOptions struct { RequireLogin bool RequirePermission []string OptionLogin bool Resource string Action string Name string LogRequest bool Labels util.MapStr Features map[string]bool Tags []string }
Define HandlerOptions to hold the state of all options
func (*HandlerOptions) Feature ¶ added in v1.1.5
func (option *HandlerOptions) Feature(feature string) bool
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 Option ¶ added in v1.1.4
type Option func(*HandlerOptions)
Define the Option type (function that modifies HandlerOptions)
func AllowPublicAccess ¶ added in v1.1.4
func AllowPublicAccess() Option
func OptionLogin ¶ added in v1.1.4
func OptionLogin() Option
func RequirePermission ¶ added in v1.1.5
type OptionRegistry ¶ added in v1.1.4
type OptionRegistry struct {
// contains filtered or unexported fields
}
Registry to store options for each method or route
func NewOptionRegistry ¶ added in v1.1.4
func NewOptionRegistry() *OptionRegistry
NewOptionRegistry creates a new registry
func (OptionRegistry) Get ¶ added in v1.1.4
func (o OptionRegistry) Get(method Method, pattern string) (options *HandlerOptions, ok bool)
func (OptionRegistry) GetKey ¶ added in v1.1.4
func (o OptionRegistry) GetKey(method Method, pattern string) string
func (OptionRegistry) Register ¶ added in v1.1.4
func (o OptionRegistry) Register(method Method, pattern string, options *HandlerOptions)
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 RegisteredAPIHandler ¶ added in v1.1.4
type RegisteredAPIHandler struct { Options *HandlerOptions Handler func(w http.ResponseWriter, req *http.Request, ps httprouter.Params) }
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"` }
func CreateResponse ¶
func DeleteResponse ¶
func UpdateResponse ¶
type Result ¶
type Result struct { Total int64 `json:"total"` Result interface{} `json:"result"` }
Result is a general json result
type UIFilters ¶ added in v1.1.4
type UIFilters interface { // ApplyFilter wraps an HTTP handler with filter logic ApplyFilter( method string, pattern string, options *HandlerOptions, next httprouter.Handle, ) httprouter.Handle // GetPriority determines execution order (lower values execute first) GetPriority() int }