Documentation ¶
Index ¶
- Constants
- func BuildRouteHandler(route *Route, schema interface{}) (func(ctx *Context), error)
- func GetRouteGroup(schema interface{}) string
- func GetTrace() string
- func GroupRoutePath(route *Route, schema interface{})
- func HTTPRequest2Invocation(req *restful.Request, schema, operation string, resp *restful.Response) (*invocation.Invocation, error)
- func Invocation2HTTPRequest(inv *invocation.Invocation, req *restful.Request)
- func Register2GoRestful(routeSpec Route, ws *restful.WebService, handler restful.RouteFunction) error
- func WrapHandlerChain(route *Route, schema interface{}, schemaName string, opts server.Options) (restful.RouteFunction, error)
- type Context
- func (bs *Context) AddHeader(header string, value string)
- func (bs *Context) ReadBodyParameter(name string) (string, error)
- func (bs *Context) ReadEntity(schema interface{}) (err error)
- func (bs *Context) ReadHeader(name string) string
- func (bs *Context) ReadPathParameter(name string) string
- func (bs *Context) ReadPathParameters() map[string]string
- func (bs *Context) ReadQueryEntity(schema interface{}) (err error)
- func (bs *Context) ReadQueryParameter(name string) string
- func (bs *Context) ReadRequest() *http.Request
- func (bs *Context) ReadResponseWriter() http.ResponseWriter
- func (bs *Context) ReadRestfulRequest() *restful.Request
- func (bs *Context) ReadRestfulResponse() *restful.Response
- func (bs *Context) Write(body []byte) error
- func (bs *Context) WriteError(httpStatus int, err error) error
- func (bs *Context) WriteHeader(httpStatus int)
- func (bs *Context) WriteHeaderAndJSON(status int, value interface{}, contentType string) error
- func (bs *Context) WriteJSON(value interface{}, contentType string) error
- type Parameters
- type ResourceHandler
- type Returns
- type Route
- type RouteGroup
- type Router
Constants ¶
const ( //Name is a variable of type string which indicates the protocol being used Name = "rest" ProfileRouteRuleSubPath = "route-rule" ProfileDiscoverySubPath = "discovery" MimeFile = "application/octet-stream" MimeMult = "multipart/form-data" )
constants for metric path and name
const ( Path = "path" Query = "query" )
const for doc
const HeaderAuth = "Authorization"
HeaderAuth is const
Variables ¶
This section is empty.
Functions ¶
func BuildRouteHandler ¶
BuildRouteHandler build handler func from ResourceFunc or ResourceFuncName
func GetRouteGroup ¶
func GetRouteGroup(schema interface{}) string
GetRouteGroup is to return a router group path
func GroupRoutePath ¶
func GroupRoutePath(route *Route, schema interface{})
GroupRoutePath add group route path to route
func HTTPRequest2Invocation ¶
func HTTPRequest2Invocation(req *restful.Request, schema, operation string, resp *restful.Response) (*invocation.Invocation, error)
HTTPRequest2Invocation convert http request to uniform invocation data format
func Invocation2HTTPRequest ¶
func Invocation2HTTPRequest(inv *invocation.Invocation, req *restful.Request)
Invocation2HTTPRequest convert invocation back to http request, set down all meta data
func Register2GoRestful ¶
func Register2GoRestful(routeSpec Route, ws *restful.WebService, handler restful.RouteFunction) error
Register2GoRestful register http handler to go-restful framework
Types ¶
type Context ¶
Context is a struct which has both request and response objects and request context
func NewBaseServer ¶
NewBaseServer is a function which return context
func (*Context) ReadBodyParameter ¶
ReadBodyParameter used to read body parameter of a request
func (*Context) ReadEntity ¶
ReadEntity is request reader
func (*Context) ReadHeader ¶
ReadHeader is used to read header of request
func (*Context) ReadPathParameter ¶
ReadPathParameter is used to read path parameter of a request
func (*Context) ReadPathParameters ¶
ReadPathParameters used to read multiple path parameters of a request
func (*Context) ReadQueryEntity ¶
ReadQueryEntity is used to read query parameters into a specified struct. The struct tag should be `form` like:
type QueryRequest struct { Name string `form:"name"` Password string `form:"password"` }
func (*Context) ReadQueryParameter ¶
ReadQueryParameter is used to read query parameter of a request
func (*Context) ReadRequest ¶
ReadRequest return a native net/http request
func (*Context) ReadResponseWriter ¶
func (bs *Context) ReadResponseWriter() http.ResponseWriter
ReadResponseWriter return a native net/http ResponseWriter
func (*Context) ReadRestfulRequest ¶
func (bs *Context) ReadRestfulRequest() *restful.Request
ReadRestfulRequest return a native go-restful request
func (*Context) ReadRestfulResponse ¶
func (bs *Context) ReadRestfulResponse() *restful.Response
ReadRestfulResponse return a native go-restful Response
func (*Context) WriteError ¶
WriteError is a function used to write error into a response
func (*Context) WriteHeader ¶
WriteHeader is the response head writer
func (*Context) WriteHeaderAndJSON ¶
WriteHeaderAndJSON used to write head and JSON file in to response
type Parameters ¶
type Parameters struct { Name string //parameter name DataType string // string, int etc ParamType int //restful.QueryParameterKind or restful.PathParameterKind Desc string Required bool }
Parameters describe parameters in url path or query params
type ResourceHandler ¶
type ResourceHandler struct {
// contains filtered or unexported fields
}
ResourceHandler wraps go-chassis restful function
func (*ResourceHandler) Handle ¶
func (h *ResourceHandler) Handle(chain *handler.Chain, inv *invocation.Invocation, cb invocation.ResponseCallBack)
Handle is to handle the router related things
type Returns ¶
type Returns struct { Code int // http response code Message string Model interface{} // response body structure Headers map[string]restful.Header }
Returns describe response doc
type Route ¶
type Route struct { Method string //Method is one of the following: GET,PUT,POST,DELETE. required Path string //Path contains a path pattern. required ResourceFunc func(ctx *Context) //the func this API calls. you must set this field or ResourceFunc, if you set both, ResourceFunc will be used ResourceFuncName string //the func this API calls. you must set this field or ResourceFunc FuncDesc string //tells what this route is all about. Optional. Parameters []*Parameters //Parameters is a slice of request parameters for a single endpoint Optional. Returns []*Returns //what kind of response this API returns. Optional. Read interface{} //Read tells what resource type will be read from the request payload. Optional. Consumes []string //Consumes specifies that this WebService can consume one or more MIME types. Produces []string //Produces specifies that this WebService can produce one or more MIME types. Metadata map[string]interface{} //Metadata adds or updates a key=value pair to api }
Route describe http route path and swagger specifications for API
func GetRouteSpecs ¶
GetRouteSpecs is to return a rest API specification of a go struct
type RouteGroup ¶
type RouteGroup interface { //GroupPath if return non-zero-value, it would be appended to route as prefix GroupPath() string }
RouteGroup is to define the route group name
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package api supply a bunch of common http handler that could be mounted on you rest server and expose ability for example: prometheus metrics will be exported on /metrics api
|
Package api supply a bunch of common http handler that could be mounted on you rest server and expose ability for example: prometheus metrics will be exported on /metrics api |