api

package
v0.10.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 20, 2018 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var RegisteredAPIFuncHandler map[string]func(http.ResponseWriter, *http.Request)

RegisteredAPIFuncHandler is a hub for registered api

View Source
var RegisteredAPIHandler map[string]http.Handler

RegisteredAPIHandler is a hub for registered api

View Source
var RegisteredAPIMethodHandler map[string]map[string]func(w http.ResponseWriter, req *http.Request, ps httprouter.Params)

RegisteredAPIMethodHandler is a hub for registered api

View Source
var RegisteredUIFuncHandler map[string]func(http.ResponseWriter, *http.Request)

RegisteredUIFuncHandler is a hub for registered ui handler

View Source
var RegisteredUIHandler map[string]http.Handler

RegisteredUIHandler is a hub for registered ui handler

View Source
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 CheckPermission(w http.ResponseWriter, r *http.Request, requiredPermission string) bool

func CheckPermissions added in v0.10.0

func CheckPermissions(w http.ResponseWriter, r *http.Request, requiredPermissions []string) bool

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

func GetPagination(from, size, total int, url string, param map[string]interface{}) string

GetPagination return a pagination html code snippet

func GetSession

func GetSession(w http.ResponseWriter, r *http.Request, key string) (bool, interface{})

GetSession return session by session key

func GetSessionStore added in v0.10.0

func GetSessionStore(r *http.Request, key string) (*sessions.Session, error)

func HandleAPI

func HandleAPI(pattern string, handler http.Handler)

HandleAPI register api handler

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 HandleUI

func HandleUI(pattern string, handler http.Handler)

HandleUI register ui request 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 Login added in v0.10.0

func Login(w http.ResponseWriter, r *http.Request, user, role string)

func Logout added in v0.10.0

func Logout(w http.ResponseWriter, r *http.Request)

func NeedPermission added in v0.10.0

func NeedPermission(permission string, h httprouter.Handle) httprouter.Handle

func SetFlash

func SetFlash(w http.ResponseWriter, r *http.Request, msg string) bool

SetFlash set flash value

func SetSession

func SetSession(w http.ResponseWriter, r *http.Request, key string, value interface{}) bool

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

func (handler Handler) EncodeJSON(v interface{}) (b []byte, err error)

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) Get

func (handler Handler) Get(req *http.Request, key string, defaultValue string) string

Get http parameter or return default value

func (Handler) GetIntOrDefault

func (handler Handler) GetIntOrDefault(r *http.Request, key string, defaultValue int) int

GetIntOrDefault return parameter or default, data type is int

func (Handler) GetJSON added in v0.9.0

func (handler Handler) GetJSON(r *http.Request) (*jsonq.JsonQuery, error)

GetJSON return json input

func (Handler) GetParameter

func (handler Handler) GetParameter(r *http.Request, key string) string

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

func (handler Handler) GetRawBody(r *http.Request) ([]byte, error)

GetRawBody return raw http request body

func (Handler) Write

func (handler Handler) Write(w http.ResponseWriter, b []byte) (int, error)

Write response to client

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

type Method

type Method string

Method is object of http method

const (
	// GET is http get method
	GET Method = "GET"
	// POST is http post method
	POST Method = "POST"
	// PUT is http put method
	PUT Method = "PUT"
	// DELETE is http delete method
	DELETE Method = "DELETE"
	// HEAD is http head method
	HEAD Method = "HEAD"
)

func (Method) String

func (method Method) String() string

String return http method as string

type Result

type Result struct {
	Total  int         `json:"total"`
	Result interface{} `json:"result"`
}

Result is a general json result

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL