Documentation ¶
Index ¶
- func DefaultRequestEncoder(_ context.Context, contentType string, in interface{}) ([]byte, error)
- func DefaultResponseDecoder(_ context.Context, rsp *http.Response, v interface{}) error
- func EncodeURL(pathTemplate string, msg interface{}, needQuery bool) string
- func GetTransportFromRequest(r *http.Request) transport.ITransport
- func SetOperation(ctx context.Context, op string)
- type CallOption
- func AddRequestHeader(key, value string) CallOption
- func OnResponse(onResponse func(*http.Response) error) CallOption
- func Operation(operation string) CallOption
- func PathTemplate(pattern string) CallOption
- func RequestHeader(header http.Header) CallOption
- func SetRequestContentType(contentType string) CallOption
- type Client
- type ClientOption
- func WithEndpoint(endpoint string) ClientOption
- func WithMiddlewares(m ...middleware.Middleware) ClientOption
- func WithRequestEncoder(encoder EncodeRequestFunc) ClientOption
- func WithResponseDecoder(decoder DecodeResponseFunc) ClientOption
- func WithTLSConfig(c *tls.Config) ClientOption
- func WithTimeout(d time.Duration) ClientOption
- func WithTransport(trans http.RoundTripper) ClientOption
- func WithUserAgent(ua string) ClientOption
- type Context
- type DecodeResponseFunc
- type EncodeRequestFunc
- type ErrorEncoder
- type IHttpRouter
- type IRedirect
- type IRouteMethod
- type IRouter
- type IRouterCoder
- type IRouterSetting
- type RequestDecoder
- type ResponseEncoder
- type RouteInfo
- type Router
- func (r *Router) CONNECT(path string, h http.HandlerFunc, m ...middleware.HttpMiddleware)
- func (r *Router) DELETE(path string, h http.HandlerFunc, m ...middleware.HttpMiddleware)
- func (r *Router) GET(path string, h http.HandlerFunc, m ...middleware.HttpMiddleware)
- func (r *Router) Group(prefix string, middlewares ...middleware.HttpMiddleware) *Router
- func (r *Router) HEAD(path string, h http.HandlerFunc, m ...middleware.HttpMiddleware)
- func (r *Router) Handle(path string, h http.Handler)
- func (r *Router) HandleFunc(path string, h http.HandlerFunc)
- func (r *Router) HandleHeader(h http.HandlerFunc, headerPairs ...string)
- func (r *Router) HandlePrefix(prefix string, h http.Handler)
- func (r *Router) OPTIONS(path string, h http.HandlerFunc, m ...middleware.HttpMiddleware)
- func (r *Router) PATCH(path string, h http.HandlerFunc, m ...middleware.HttpMiddleware)
- func (r *Router) POST(path string, h http.HandlerFunc, m ...middleware.HttpMiddleware)
- func (r *Router) PUT(path string, h http.HandlerFunc, m ...middleware.HttpMiddleware)
- func (r *Router) ServeHTTP(res http.ResponseWriter, req *http.Request)
- func (r *Router) TRACE(path string, h http.HandlerFunc, m ...middleware.HttpMiddleware)
- func (r *Router) Use(mws ...middleware.HttpMiddleware)
- func (r *Router) WalkRoute(fn WalkRouteFunc) error
- type RouterCfg
- type Server
- func (s *Server) Endpoint() (*url.URL, error)
- func (s *Server) GetRouter() IRouter
- func (s *Server) Middlewares() []middleware.Middleware
- func (s *Server) NewRouteGroup(prefix string, httpMiddlewares ...middleware.HttpMiddleware) *Router
- func (s *Server) ServeHTTP(res http.ResponseWriter, req *http.Request)
- func (s *Server) SetMiddlewares(mws ...middleware.Middleware)
- func (s *Server) Start(ctx context.Context) error
- func (s *Server) Stop(ctx context.Context) error
- type ServerOption
- func Address(addr string) ServerOption
- func Endpoint(endpoint *url.URL) ServerOption
- func Listener(lis net.Listener) ServerOption
- func Network(network string) ServerOption
- func RouterCoder(coder IRouterCoder) ServerOption
- func RouterMethodNotAllowedHandler(handler http.Handler) ServerOption
- func RouterNotFoundHandler(handler http.Handler) ServerOption
- func RouterPathPrefix(prefix string) ServerOption
- func RouterSkipClean(skipClean bool) ServerOption
- func RouterStrictSlash(strictSlash bool) ServerOption
- func RouterUseEncodedPath() ServerOption
- func SetMiddlewares(mws ...middleware.Middleware) ServerOption
- func TLSConfig(c *tls.Config) ServerOption
- func Timeout(timeout time.Duration) ServerOption
- type Target
- type Transport
- type WalkRouteFunc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DefaultRequestEncoder ¶
func DefaultResponseDecoder ¶
DefaultResponseDecoder is an HTTP response decoder.
func GetTransportFromRequest ¶
func GetTransportFromRequest(r *http.Request) transport.ITransport
func SetOperation ¶
SetOperation sets the transport Operation.
Types ¶
type CallOption ¶
type CallOption func(*callInfo)
func AddRequestHeader ¶
func AddRequestHeader(key, value string) CallOption
func OnResponse ¶
func OnResponse(onResponse func(*http.Response) error) CallOption
func Operation ¶
func Operation(operation string) CallOption
func RequestHeader ¶
func RequestHeader(header http.Header) CallOption
func SetRequestContentType ¶
func SetRequestContentType(contentType string) CallOption
SetRequestContentType with request content type.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is an HTTP client.
func NewClient ¶
func NewClient(opts ...ClientOption) (*Client, error)
NewClient returns an HTTP client.
type ClientOption ¶
type ClientOption func(*Client)
ClientOption is HTTP client option.
func WithMiddlewares ¶
func WithMiddlewares(m ...middleware.Middleware) ClientOption
WithMiddlewares with client middleware.
func WithRequestEncoder ¶
func WithRequestEncoder(encoder EncodeRequestFunc) ClientOption
WithRequestEncoder with client request encoder.
func WithResponseDecoder ¶
func WithResponseDecoder(decoder DecodeResponseFunc) ClientOption
WithResponseDecoder with client response decoder.
func WithTimeout ¶
func WithTimeout(d time.Duration) ClientOption
WithTimeout with client request timeout.
func WithTransport ¶
func WithTransport(trans http.RoundTripper) ClientOption
WithTransport with client transport.
func WithUserAgent ¶
func WithUserAgent(ua string) ClientOption
WithUserAgent with client user agent.
type Context ¶
type Context interface { context.Context Vars() url.Values Query() url.Values Form() url.Values Header() http.Header Request() *http.Request Response() http.ResponseWriter Bind(interface{}) error BindVars(interface{}) error BindQuery(interface{}) error BindForm(interface{}) error Returns(interface{}, error) error Result(int, interface{}) error JSON(int, interface{}) error XML(int, interface{}) error String(int, string) error Blob(int, string, []byte) error Stream(int, string, io.Reader) error Reset(http.ResponseWriter, *http.Request) ReturnError(error) }
Context is an HTTP Context.
type DecodeResponseFunc ¶
DecodeResponseFunc is response decode func.
type EncodeRequestFunc ¶
type EncodeRequestFunc func(ctx context.Context, contentType string, in interface{}) (body []byte, err error)
EncodeRequestFunc is request encode func.
type ErrorEncoder ¶
type ErrorEncoder func(http.ResponseWriter, *http.Request, error)
ErrorEncoder is encode error func.
type IHttpRouter ¶
type IHttpRouter interface { ServeHTTP(res http.ResponseWriter, req *http.Request) Use(mws ...middleware.HttpMiddleware) Group(prefix string, middlewares ...middleware.HttpMiddleware) *Router Handle(path string, h http.Handler) HandlePrefix(prefix string, h http.Handler) HandleFunc(path string, h http.HandlerFunc) HandleHeader(h http.HandlerFunc, headerPairs ...string) }
type IRedirect ¶
func NewRedirect ¶
NewRedirect new a redirect with url, which may be a path relative to the request path. The provided code should be in the 3xx range and is usually StatusMovedPermanently, StatusFound or StatusSeeOther. If the Content-Type header has not been set, Redirect sets it to "text/html; charset=utf-8" and writes a small HTML body. Setting the Content-Type header to any value, including nil, disables that behavior.
type IRouteMethod ¶
type IRouteMethod interface { GET(path string, h http.HandlerFunc, m ...middleware.HttpMiddleware) HEAD(path string, h http.HandlerFunc, m ...middleware.HttpMiddleware) POST(path string, h http.HandlerFunc, m ...middleware.HttpMiddleware) PUT(path string, h http.HandlerFunc, m ...middleware.HttpMiddleware) PATCH(path string, h http.HandlerFunc, m ...middleware.HttpMiddleware) DELETE(path string, h http.HandlerFunc, m ...middleware.HttpMiddleware) CONNECT(path string, h http.HandlerFunc, m ...middleware.HttpMiddleware) OPTIONS(path string, h http.HandlerFunc, m ...middleware.HttpMiddleware) TRACE(path string, h http.HandlerFunc, m ...middleware.HttpMiddleware) }
type IRouter ¶
type IRouter interface { IHttpRouter IRouteMethod WalkRoute(fn WalkRouteFunc) error }
type IRouterCoder ¶
type IRouterCoder interface { BindVars() RequestDecoder BindQuery() RequestDecoder BindForm() RequestDecoder BindBody() RequestDecoder ResponseEncoder() ResponseEncoder ErrorEncoder() ErrorEncoder }
type IRouterSetting ¶
type IRouterSetting interface { UseEncodedPath() bool SetUseEncodedPath(bool) StrictSlash() bool SetStrictSlash(bool) SkipClean() bool SetSkipClean(bool) Prefix() string SetPrefix(string) NotFoundHandler() http.Handler SetNotFoundHandler(handler http.Handler) NotAllowedHandler() http.Handler SetNotAllowedHandler(handler http.Handler) }
type RequestDecoder ¶
RequestDecoder is decode request func.
type ResponseEncoder ¶
ResponseEncoder is encode response func.
type Router ¶
type Router struct { *RouterCfg // contains filtered or unexported fields }
Router is an HTTP coder.
func (*Router) CONNECT ¶
func (r *Router) CONNECT(path string, h http.HandlerFunc, m ...middleware.HttpMiddleware)
func (*Router) DELETE ¶
func (r *Router) DELETE(path string, h http.HandlerFunc, m ...middleware.HttpMiddleware)
func (*Router) GET ¶
func (r *Router) GET(path string, h http.HandlerFunc, m ...middleware.HttpMiddleware)
func (*Router) Group ¶
func (r *Router) Group(prefix string, middlewares ...middleware.HttpMiddleware) *Router
func (*Router) HEAD ¶
func (r *Router) HEAD(path string, h http.HandlerFunc, m ...middleware.HttpMiddleware)
func (*Router) HandleFunc ¶
func (r *Router) HandleFunc(path string, h http.HandlerFunc)
func (*Router) HandleHeader ¶
func (r *Router) HandleHeader(h http.HandlerFunc, headerPairs ...string)
func (*Router) OPTIONS ¶
func (r *Router) OPTIONS(path string, h http.HandlerFunc, m ...middleware.HttpMiddleware)
func (*Router) PATCH ¶
func (r *Router) PATCH(path string, h http.HandlerFunc, m ...middleware.HttpMiddleware)
func (*Router) POST ¶
func (r *Router) POST(path string, h http.HandlerFunc, m ...middleware.HttpMiddleware)
func (*Router) PUT ¶
func (r *Router) PUT(path string, h http.HandlerFunc, m ...middleware.HttpMiddleware)
func (*Router) TRACE ¶
func (r *Router) TRACE(path string, h http.HandlerFunc, m ...middleware.HttpMiddleware)
func (*Router) Use ¶
func (r *Router) Use(mws ...middleware.HttpMiddleware)
func (*Router) WalkRoute ¶
func (r *Router) WalkRoute(fn WalkRouteFunc) error
type RouterCfg ¶
type RouterCfg struct { // If true, "/path/foo%2Fbar/to" will match the path "/path/{var}/to" UseEncodedPath bool // If true, when the path pattern is "/path/", accessing "/path" will // redirect to the former and vice versa. StrictSlash bool // If true, when the path pattern is "/path//to", accessing "/path//to" // will not redirect SkipClean bool // Configurable Handler to be used when no route matches. NotFoundHandler http.Handler // Configurable Handler to be used when the request method does not match the route. MethodNotAllowedHandler http.Handler RootPrefix string Coder IRouterCoder }
func NewRouterCfg ¶
func NewRouterCfg() *RouterCfg
type Server ¶
Server is an HTTP server wrappedCtx.
func NewServer ¶
func NewServer(opts ...ServerOption) *Server
func (*Server) Middlewares ¶
func (s *Server) Middlewares() []middleware.Middleware
func (*Server) NewRouteGroup ¶
func (s *Server) NewRouteGroup(prefix string, httpMiddlewares ...middleware.HttpMiddleware) *Router
func (*Server) ServeHTTP ¶
func (s *Server) ServeHTTP(res http.ResponseWriter, req *http.Request)
ServeHTTP should write reply headers and data to the ResponseWriter and then return.
func (*Server) SetMiddlewares ¶
func (s *Server) SetMiddlewares(mws ...middleware.Middleware)
type ServerOption ¶
type ServerOption func(*Server)
ServerOption is an HTTP server option.
func RouterMethodNotAllowedHandler ¶
func RouterMethodNotAllowedHandler(handler http.Handler) ServerOption
RouterMethodNotAllowedHandler
func RouterNotFoundHandler ¶
func RouterNotFoundHandler(handler http.Handler) ServerOption
RouterNotFoundHandler
func RouterPathPrefix ¶
func RouterPathPrefix(prefix string) ServerOption
RouterPathPrefix with mux's PathPrefix, coder will replace by a subrouter that start with RootPrefix.
func RouterSkipClean ¶
func RouterSkipClean(skipClean bool) ServerOption
RouterSkipClean with mux's SkipClean
func RouterStrictSlash ¶
func RouterStrictSlash(strictSlash bool) ServerOption
RouterStrictSlash with mux's StrictSlash If true, when the path pattern is "/path/", accessing "/path" will redirect to the former and vice versa.
func RouterUseEncodedPath ¶
func RouterUseEncodedPath() ServerOption
RouterUseEncodedPath with mux's SkipClean
func SetMiddlewares ¶
func SetMiddlewares(mws ...middleware.Middleware) ServerOption
SetMiddlewares with server middlewares.
type Transport ¶
type Transport struct { transport.BaseTransport Request *http.Request }
func (*Transport) GetRequest ¶
type WalkRouteFunc ¶
WalkRouteFunc is the type of the function called for each route visited by Walk.