Documentation
¶
Index ¶
- Variables
- func BasicAuth(h httprouter.Handle, requiredUser, requiredPassword string) httprouter.Handle
- func CheckPermission(w http.ResponseWriter, r *http.Request, requiredPermission string) bool
- func CheckPermissions(w http.ResponseWriter, r *http.Request, requiredPermissions []string) bool
- func EnableAuth(enable bool)
- func GetFlash(w http.ResponseWriter, r *http.Request) (bool, []interface{})
- func GetLoginInfo(w http.ResponseWriter, r *http.Request) (user, role string)
- func GetPagination(from, size, total int, url string, param map[string]interface{}) string
- func GetSession(w http.ResponseWriter, r *http.Request, key string) (bool, interface{})
- func GetSessionStore(r *http.Request, key string) (*sessions.Session, error)
- func HandleAPI(pattern string, handler http.Handler)
- 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 IsAuthEnable() bool
- func Login(w http.ResponseWriter, r *http.Request, user, role string)
- func Logout(w http.ResponseWriter, r *http.Request)
- func NeedPermission(permission string, h httprouter.Handle) httprouter.Handle
- func SetFlash(w http.ResponseWriter, r *http.Request, msg string) bool
- func SetSession(w http.ResponseWriter, r *http.Request, key string, value interface{}) bool
- type Handler
- func (handler Handler) EncodeJSON(v interface{}) (b []byte, err error)
- func (handler Handler) Error(w http.ResponseWriter, err error)
- func (handler Handler) Error404(w http.ResponseWriter)
- func (handler Handler) Error500(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) 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) Write(w http.ResponseWriter, b []byte) (int, 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 int, v interface{}, statusCode int) error
- type Method
- type Result
Constants ¶
This section is empty.
Variables ¶
var RegisteredAPIFuncHandler map[string]func(http.ResponseWriter, *http.Request)
RegisteredAPIFuncHandler is a hub for registered api
var RegisteredAPIHandler map[string]http.Handler
RegisteredAPIHandler is a hub for registered api
var RegisteredAPIMethodHandler map[string]map[string]func(w http.ResponseWriter, req *http.Request, ps httprouter.Params)
RegisteredAPIMethodHandler is a hub for registered api
var RegisteredUIFuncHandler map[string]func(http.ResponseWriter, *http.Request)
RegisteredUIFuncHandler is a hub for registered ui handler
var RegisteredUIHandler map[string]http.Handler
RegisteredUIHandler is a hub for registered ui handler
var RegisteredUIMethodHandler map[string]map[string]func(w http.ResponseWriter, req *http.Request, ps httprouter.Params)
RegisteredUIMethodHandler is a hub for registered ui handler
Functions ¶
func BasicAuth ¶
func BasicAuth(h httprouter.Handle, requiredUser, requiredPassword string) httprouter.Handle
BasicAuth register api with basic auth
func CheckPermission ¶ added in v0.10.0
func CheckPermissions ¶ added in v0.10.0
func EnableAuth ¶ added in v0.10.0
func EnableAuth(enable bool)
func GetFlash ¶
func GetFlash(w http.ResponseWriter, r *http.Request) (bool, []interface{})
GetFlash get flash value
func GetLoginInfo ¶ added in v0.10.0
func GetLoginInfo(w http.ResponseWriter, r *http.Request) (user, role string)
func GetPagination ¶ added in v0.9.0
GetPagination return a pagination html code snippet
func GetSession ¶
GetSession return session by session key
func GetSessionStore ¶ added in v0.10.0
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 IsAuthEnable ¶ added in v0.10.0
func IsAuthEnable() bool
func NeedPermission ¶ added in v0.10.0
func NeedPermission(permission string, h httprouter.Handle) httprouter.Handle
func SetSession ¶
SetSession set session by session key and session value
Types ¶
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
Handler is the object of http handler
func (Handler) EncodeJSON ¶ added in v0.9.0
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) 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) WriteHeader ¶
func (handler Handler) WriteHeader(w http.ResponseWriter, code int)
WriteHeader write status code to http header
func (Handler) WriteJSON ¶ added in v0.9.0
func (handler Handler) WriteJSON(w http.ResponseWriter, v interface{}, statusCode int) error
WriteJSON output signal result with json format
func (Handler) WriteJSONHeader ¶ added in v0.9.0
func (handler Handler) WriteJSONHeader(w http.ResponseWriter)
WriteJSONHeader will write standard json header
func (Handler) WriteJSONListResult ¶ added in v0.9.0
func (handler Handler) WriteJSONListResult(w http.ResponseWriter, total int, v interface{}, statusCode int) error
WriteJSONListResult output result list to json format