Documentation ¶
Index ¶
- Constants
- 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 GetPermissionsByRole(role string) (*hashset.Set, error)
- func GetSession(w http.ResponseWriter, 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 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
- func StartAPI(cfg *config.Config)
- type APIConfig
- 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) 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) 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) Write(w http.ResponseWriter, b []byte) (int, error)
- func (handler Handler) WriteAckJSON(w http.ResponseWriter, ack bool) 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 ¶
const ( ROLE_GUEST string = "guest" ROLE_ADMIN string = "admin" )
const ( //GUEST PERMISSION_SNAPSHOT_VIEW string = "view_snapshot" //ADMIN PERMISSION_ADMIN_MINIMAL string = "admin_minimal" )
Variables ¶
This section is empty.
Functions ¶
func BasicAuth ¶
func BasicAuth(h httprouter.Handle, requiredUser, requiredPassword string) httprouter.Handle
BasicAuth register api with basic auth
func CheckPermission ¶
func CheckPermissions ¶
func EnableAuth ¶
func EnableAuth(enable bool)
func GetFlash ¶
func GetFlash(w http.ResponseWriter, r *http.Request) (bool, []interface{})
GetFlash get flash value
func GetLoginInfo ¶
func GetLoginInfo(w http.ResponseWriter, r *http.Request) (user, role string)
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 IsAuthEnable ¶
func IsAuthEnable() bool
func NeedPermission ¶
func NeedPermission(permission string, h httprouter.Handle) httprouter.Handle
func SetSession ¶
SetSession set session by session key and session value
Types ¶
type APIConfig ¶
type APIConfig struct { Enabled bool `config:"enabled"` TLSConfig config.TLSConfig `config:"tls"` NetworkConfig config.NetworkConfig `config:"network"` }
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) 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) WriteAckJSON ¶
func (handler Handler) WriteAckJSON(w http.ResponseWriter, ack bool) 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
WriteJSON output signal result with json format
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 int, v interface{}, statusCode int) error
WriteJSONListResult output result list to json format