api

package
v1.0.6 Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2020 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

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

type HandlerFunc func(ctx context.Context, rw http.ResponseWriter, req *http.Request) error

HandlerFunc is the http request handler.

type HandlerSpec

type HandlerSpec struct {
	Method      string
	Path        string
	HandlerFunc HandlerFunc
}

HandlerSpec describes an HTTP api

type ValidateFunc

type ValidateFunc func(registry strfmt.Registry) error

ValidateFunc validates the request parameters.

Jump to

Keyboard shortcuts

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