Documentation ¶
Index ¶
- Variables
- func HandleErrorResponse(w http.ResponseWriter, err error) error
- func ParseJSONRequest(req io.Reader, target interface{}, validator ValidateFunc) error
- func SendResponse(w http.ResponseWriter, code int, data interface{}) error
- func WrapHandler(handler HandlerFunc) http.HandlerFunc
- type HandlerFunc
- type HandlerSpec
- type ValidateFunc
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // V1 is recommended, any new API should be registered in this category. V1 = newCategory("v1 api", "/api/v1") // Extension allows users to register extension APIs into supernode. // Customized APIs should be registered by using this category. // It can distinguish between Dragonfly's core APIs and customized APIs. // And supernode provides `/api/ext` to list all the registered APIs in this // category. Extension = newCategory("extension api", "/api/ext") // Legacy is deprecated, just for compatibility with the old version, // please do not use it to add new API. Legacy = newCategory("legacy api", "") )
Functions ¶
func HandleErrorResponse ¶
func HandleErrorResponse(w http.ResponseWriter, err error) error
HandleErrorResponse handles err from server side and constructs response for client side.
func ParseJSONRequest ¶
func ParseJSONRequest(req io.Reader, target interface{}, validator ValidateFunc) error
ParseJSONRequest parses the request JSON parameter to a target object.
func SendResponse ¶
func SendResponse(w http.ResponseWriter, code int, data interface{}) error
SendResponse encodes response in json.
TODO:
Should the response body should be empty if the data is nil or empty string? Now it's incompatible with the client.
func WrapHandler ¶
func WrapHandler(handler HandlerFunc) http.HandlerFunc
WrapHandler converts the 'api.HandlerFunc' into type 'http.HandlerFunc' and format the error response if any error happens.
Types ¶
type HandlerFunc ¶
HandlerFunc is the http request handler.
type HandlerSpec ¶
type HandlerSpec struct { Method string Path string HandlerFunc HandlerFunc }
HandlerSpec describes an HTTP api
type ValidateFunc ¶
ValidateFunc validates the request parameters.
Click to show internal directories.
Click to hide internal directories.