Documentation ¶
Index ¶
- Constants
- func CodecForRequest(r *http.Request, name string) (encoding.Codec, bool)
- func CodecForResponse(r *http.Response) encoding.Codec
- func DefaultErrorDecoder(ctx context.Context, res *http.Response) error
- func DefaultErrorEncoder(w http.ResponseWriter, r *http.Request, se error)
- func DefaultRequestDecoder(r *http.Request, v interface{}) error
- func DefaultRequestEncoder(ctx context.Context, contentType string, in interface{}) ([]byte, error)
- func DefaultResponseDecoder(ctx context.Context, res *http.Response, v interface{}) error
- func DefaultResponseEncoder(w http.ResponseWriter, r *http.Request, v interface{}) error
- func SetOperation(ctx context.Context, op string)
- type CallOption
- type Client
- type ClientOption
- func WithBalancer(b balancer.Balancer) ClientOption
- func WithDiscovery(d registry.Discovery) ClientOption
- func WithEndpoint(endpoint string) ClientOption
- func WithErrorDecoder(errorDecoder DecodeErrorFunc) ClientOption
- func WithMiddleware(m ...middleware.Middleware) ClientOption
- func WithRequestEncoder(encoder EncodeRequestFunc) ClientOption
- func WithResponseDecoder(decoder DecodeResponseFunc) ClientOption
- func WithTimeout(d time.Duration) ClientOption
- func WithTransport(trans http.RoundTripper) ClientOption
- func WithUserAgent(ua string) ClientOption
- type ContentTypeCallOption
- type Context
- type DecodeErrorFunc
- type DecodeRequestFunc
- type DecodeResponseFunc
- type EmptyCallOption
- type EncodeErrorFunc
- type EncodeRequestFunc
- type EncodeResponseFunc
- type FilterFunc
- type HandlerFunc
- type OperationCallOption
- type PathTemplateCallOption
- type Route
- func (r *Route) CONNECT(path string, h HandlerFunc, m ...FilterFunc)
- func (r *Route) DELETE(path string, h HandlerFunc, m ...FilterFunc)
- func (r *Route) GET(path string, h HandlerFunc, m ...FilterFunc)
- func (r *Route) HEAD(path string, h HandlerFunc, m ...FilterFunc)
- func (r *Route) Handle(method, relativePath string, h HandlerFunc, filters ...FilterFunc)
- func (r *Route) OPTIONS(path string, h HandlerFunc, m ...FilterFunc)
- func (r *Route) PATCH(path string, h HandlerFunc, m ...FilterFunc)
- func (r *Route) POST(path string, h HandlerFunc, m ...FilterFunc)
- func (r *Route) PUT(path string, h HandlerFunc, m ...FilterFunc)
- func (r *Route) TRACE(path string, h HandlerFunc, m ...FilterFunc)
- type Server
- func (s *Server) Endpoint() (*url.URL, error)
- func (s *Server) Handle(path string, h http.Handler)
- func (s *Server) HandleFunc(path string, h http.HandlerFunc)
- func (s *Server) HandlePrefix(prefix string, h http.Handler)
- func (s *Server) Route(prefix string, filters ...FilterFunc) *Route
- func (s *Server) ServeHTTP(res http.ResponseWriter, req *http.Request)
- func (s *Server) Start(ctx context.Context) error
- func (s *Server) Stop(ctx context.Context) error
- type ServerOption
- func Address(addr string) ServerOption
- func ErrorEncoder(en EncodeErrorFunc) ServerOption
- func Filter(filters ...FilterFunc) ServerOption
- func Logger(logger log.Logger) ServerOption
- func Middleware(m ...middleware.Middleware) ServerOption
- func Network(network string) ServerOption
- func RequestDecoder(dec DecodeRequestFunc) ServerOption
- func ResponseEncoder(en EncodeResponseFunc) ServerOption
- func Timeout(timeout time.Duration) ServerOption
- type Target
- type Transport
Constants ¶
const SupportPackageIsVersion1 = true
SupportPackageIsVersion1 These constants should not be referenced from any other code.
Variables ¶
This section is empty.
Functions ¶
func CodecForRequest ¶
CodecForRequest get encoding.Codec via http.Request
func CodecForResponse ¶
CodecForResponse get encoding.Codec via http.Response
func DefaultErrorDecoder ¶
DefaultErrorDecoder is an HTTP error decoder.
func DefaultErrorEncoder ¶
func DefaultErrorEncoder(w http.ResponseWriter, r *http.Request, se error)
DefaultErrorEncoder encodes the error to the HTTP response.
func DefaultRequestDecoder ¶
DefaultRequestDecoder decodes the request body to object.
func DefaultRequestEncoder ¶
DefaultRequestEncoder is an HTTP request encoder.
func DefaultResponseDecoder ¶
DefaultResponseDecoder is an HTTP response decoder.
func DefaultResponseEncoder ¶
func DefaultResponseEncoder(w http.ResponseWriter, r *http.Request, v interface{}) error
DefaultResponseEncoder encodes the object to the HTTP response.
func SetOperation ¶
SetOperation sets the transport operation.
Types ¶
type CallOption ¶
type CallOption interface {
// contains filtered or unexported methods
}
CallOption configures a Call before it starts or extracts information from a Call after it completes.
func ContentType ¶
func ContentType(contentType string) CallOption
ContentType with request content type.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is an HTTP client.
func NewClient ¶
func NewClient(ctx context.Context, opts ...ClientOption) (*Client, error)
NewClient returns an HTTP client.
type ClientOption ¶
type ClientOption func(*clientOptions)
ClientOption is HTTP client option.
func WithBalancer ¶
func WithBalancer(b balancer.Balancer) ClientOption
WithBalancer with client balancer. Experimental Notice: This type is EXPERIMENTAL and may be changed or removed in a later release.
func WithDiscovery ¶
func WithDiscovery(d registry.Discovery) ClientOption
WithDiscovery with client discovery.
func WithErrorDecoder ¶
func WithErrorDecoder(errorDecoder DecodeErrorFunc) ClientOption
WithErrorDecoder with client error decoder.
func WithMiddleware ¶
func WithMiddleware(m ...middleware.Middleware) ClientOption
WithMiddleware 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 ContentTypeCallOption ¶
type ContentTypeCallOption struct { EmptyCallOption ContentType string }
ContentTypeCallOption is BodyCallOption
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 Middleware(middleware.Handler) middleware.Handler 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) }
Context is an HTTP Context.
type DecodeErrorFunc ¶
DecodeErrorFunc is decode error func.
type DecodeRequestFunc ¶
DecodeRequestFunc is decode request func.
type DecodeResponseFunc ¶
DecodeResponseFunc is response decode func.
type EmptyCallOption ¶
type EmptyCallOption struct{}
EmptyCallOption does not alter the Call configuration. It can be embedded in another structure to carry satellite data for use by interceptors.
type EncodeErrorFunc ¶
type EncodeErrorFunc func(http.ResponseWriter, *http.Request, error)
EncodeErrorFunc is encode error func.
type EncodeRequestFunc ¶
type EncodeRequestFunc func(ctx context.Context, contentType string, in interface{}) (body []byte, err error)
EncodeRequestFunc is request encode func.
type EncodeResponseFunc ¶
type EncodeResponseFunc func(http.ResponseWriter, *http.Request, interface{}) error
EncodeResponseFunc is encode response func.
type FilterFunc ¶
FilterFunc is a function which receives an http.Handler and returns another http.Handler.
func FilterChain ¶
func FilterChain(filters ...FilterFunc) FilterFunc
FilterChain returns a FilterFunc that specifies the chained handler for HTTP Router.
type HandlerFunc ¶
HandlerFunc defines a function to serve HTTP requests.
type OperationCallOption ¶
type OperationCallOption struct { EmptyCallOption Operation string }
OperationCallOption is set ServiceMethod for client call
type PathTemplateCallOption ¶
type PathTemplateCallOption struct { EmptyCallOption Pattern string }
PathTemplateCallOption is set path template for client call
type Route ¶
type Route struct {
// contains filtered or unexported fields
}
Route is an HTTP route.
func (*Route) CONNECT ¶
func (r *Route) CONNECT(path string, h HandlerFunc, m ...FilterFunc)
CONNECT registers a new CONNECT route for a path with matching handler in the router.
func (*Route) DELETE ¶
func (r *Route) DELETE(path string, h HandlerFunc, m ...FilterFunc)
DELETE registers a new DELETE route for a path with matching handler in the router.
func (*Route) GET ¶
func (r *Route) GET(path string, h HandlerFunc, m ...FilterFunc)
GET registers a new GET route for a path with matching handler in the router.
func (*Route) HEAD ¶
func (r *Route) HEAD(path string, h HandlerFunc, m ...FilterFunc)
HEAD registers a new HEAD route for a path with matching handler in the router.
func (*Route) Handle ¶
func (r *Route) Handle(method, relativePath string, h HandlerFunc, filters ...FilterFunc)
Handle registers a new route with a matcher for the URL path and method.
func (*Route) OPTIONS ¶
func (r *Route) OPTIONS(path string, h HandlerFunc, m ...FilterFunc)
OPTIONS registers a new OPTIONS route for a path with matching handler in the router.
func (*Route) PATCH ¶
func (r *Route) PATCH(path string, h HandlerFunc, m ...FilterFunc)
PATCH registers a new PATCH route for a path with matching handler in the router.
func (*Route) POST ¶
func (r *Route) POST(path string, h HandlerFunc, m ...FilterFunc)
POST registers a new POST route for a path with matching handler in the router.
func (*Route) PUT ¶
func (r *Route) PUT(path string, h HandlerFunc, m ...FilterFunc)
PUT registers a new PUT route for a path with matching handler in the router.
func (*Route) TRACE ¶
func (r *Route) TRACE(path string, h HandlerFunc, m ...FilterFunc)
TRACE registers a new TRACE route for a path with matching handler in the router.
type Server ¶
Server is an HTTP server wrapper.
func NewServer ¶
func NewServer(opts ...ServerOption) *Server
NewServer creates an HTTP server by options.
func (*Server) Endpoint ¶
Endpoint return a real address to registry endpoint. examples:
http://127.0.0.1:8000?isSecure=false
func (*Server) HandleFunc ¶
func (s *Server) HandleFunc(path string, h http.HandlerFunc)
HandleFunc registers a new route with a matcher for the URL path.
func (*Server) HandlePrefix ¶
HandlePrefix registers a new route with a matcher for the URL path prefix.
func (*Server) Route ¶
func (s *Server) Route(prefix string, filters ...FilterFunc) *Route
Route registers an HTTP route.
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.
type ServerOption ¶
type ServerOption func(*Server)
ServerOption is an HTTP server option.
func ErrorEncoder ¶
func ErrorEncoder(en EncodeErrorFunc) ServerOption
ErrorEncoder with error encoder.
func Middleware ¶
func Middleware(m ...middleware.Middleware) ServerOption
Middleware with service middleware option.
func RequestDecoder ¶
func RequestDecoder(dec DecodeRequestFunc) ServerOption
RequestDecoder with request decoder.
func ResponseEncoder ¶
func ResponseEncoder(en EncodeResponseFunc) ServerOption
ResponseEncoder with response encoder.
type Transport ¶
type Transport struct {
// contains filtered or unexported fields
}
Transport is an HTTP transport.
func (*Transport) PathTemplate ¶
PathTemplate returns the http path template.