Documentation ¶
Index ¶
- Constants
- func CheckResponse(res *http.Response) error
- func DecodeResponse(res *http.Response, v interface{}) error
- func DefaultErrorEncoder(err error, res http.ResponseWriter, req *http.Request)
- func DefaultRecoveryHandler(ctx context.Context, req, err interface{}) error
- func DefaultRequestDecoder(in interface{}, req *http.Request) error
- func DefaultResponseEncoder(out interface{}, res http.ResponseWriter, req *http.Request) error
- func NewClient(opts ...ClientOption) (*http.Client, error)
- func NewContext(ctx context.Context, s ServerInfo) context.Context
- func PopulateBody(msg proto.Message, req *http.Request) error
- func PopulateForm(msg proto.Message, req *http.Request) error
- func PopulateVars(msg proto.Message, req *http.Request) error
- func RequestCodec(req *http.Request) (encoding.Codec, error)
- func ResponseCodec(req *http.Request) (string, encoding.Codec, error)
- func StatusError(err error) (int, *errors.StatusError)
- func Vars(req *http.Request) map[string]string
- type Client
- type ClientDecodeErrorFunc
- type ClientOption
- func ClientErrorDecoder(d ClientDecodeErrorFunc) ClientOption
- func ClientKeepAlive(d time.Duration) ClientOption
- func ClientMaxIdleConns(n int) ClientOption
- func ClientRecoveryHandler(h RecoveryHandlerFunc) ClientOption
- func ClientTimeout(d time.Duration) ClientOption
- func ClientUserAgent(ua string) ClientOption
- type MethodDesc
- type RecoveryHandlerFunc
- type Server
- func (s *Server) Handle(path string, handler http.Handler)
- func (s *Server) HandleFunc(path string, h func(http.ResponseWriter, *http.Request))
- func (s *Server) RegisterService(sd *ServiceDesc, ss interface{})
- func (s *Server) ServeHTTP(res http.ResponseWriter, req *http.Request)
- func (s *Server) Use(srv interface{}, m ...middleware.Middleware)
- type ServerDecodeRequestFunc
- type ServerEncodeErrorFunc
- type ServerEncodeResponseFunc
- type ServerInfo
- type ServerOption
- func ServerErrorEncoder(fn ServerEncodeErrorFunc) ServerOption
- func ServerMiddleware(m ...middleware.Middleware) ServerOption
- func ServerRecoveryHandler(fn RecoveryHandlerFunc) ServerOption
- func ServerRequestDecoder(fn ServerEncodeErrorFunc) ServerOption
- func ServerResponseEncoder(fn ServerEncodeResponseFunc) ServerOption
- type ServiceDesc
- type ServiceRegistrar
Constants ¶
const SupportPackageIsVersion1 = true
SupportPackageIsVersion1 These constants should not be referenced from any other code.
Variables ¶
This section is empty.
Functions ¶
func CheckResponse ¶
CheckResponse returns an error (of type *Error) if the response status code is not 2xx.
func DecodeResponse ¶
DecodeResponse decodes the body of res into target. If there is no body, target is unchanged.
func DefaultErrorEncoder ¶
func DefaultErrorEncoder(err error, res http.ResponseWriter, req *http.Request)
DefaultErrorEncoder is default errors encoder.
func DefaultRecoveryHandler ¶
DefaultRecoveryHandler is default recovery handler.
func DefaultRequestDecoder ¶
DefaultRequestDecoder default request decoder.
func DefaultResponseEncoder ¶
func DefaultResponseEncoder(out interface{}, res http.ResponseWriter, req *http.Request) error
DefaultResponseEncoder is default response encoder.
func NewClient ¶
func NewClient(opts ...ClientOption) (*http.Client, error)
NewClient new a HTTP transport client.
func NewContext ¶
func NewContext(ctx context.Context, s ServerInfo) context.Context
NewContext returns a new Context that carries value.
func PopulateBody ¶
PopulateBody parses body payload.
func PopulateForm ¶
PopulateForm parses query parameters
func PopulateVars ¶
PopulateVars parses url parameters.
func RequestCodec ¶
RequestCodec returns request codec.
func ResponseCodec ¶
ResponseCodec returns response codec.
func StatusError ¶
func StatusError(err error) (int, *errors.StatusError)
StatusError converts error to http error.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is a HTTP transport client.
type ClientDecodeErrorFunc ¶
ClientDecodeErrorFunc is client error decoder.
type ClientOption ¶
type ClientOption func(*Client)
ClientOption is HTTP client option.
func ClientErrorDecoder ¶
func ClientErrorDecoder(d ClientDecodeErrorFunc) ClientOption
ClientErrorDecoder with client error decoder.
func ClientKeepAlive ¶
func ClientKeepAlive(d time.Duration) ClientOption
ClientKeepAlive with client keepavlie.
func ClientMaxIdleConns ¶
func ClientMaxIdleConns(n int) ClientOption
ClientMaxIdleConns with client max idle conns.
func ClientRecoveryHandler ¶
func ClientRecoveryHandler(h RecoveryHandlerFunc) ClientOption
ClientRecoveryHandler with server recovery handler.
func ClientTimeout ¶
func ClientTimeout(d time.Duration) ClientOption
ClientTimeout with client request timeout.
func ClientUserAgent ¶
func ClientUserAgent(ua string) ClientOption
ClientUserAgent with client user agent.
type MethodDesc ¶
MethodDesc represents a HTTP service's method specification.
type RecoveryHandlerFunc ¶
RecoveryHandlerFunc is recovery handler func.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server is a HTTP server wrapper.
func NewServer ¶
func NewServer(opts ...ServerOption) *Server
NewServer creates a HTTP server by options.
func (*Server) HandleFunc ¶
HandleFunc registers a new route with a matcher for the URL path.
func (*Server) RegisterService ¶
func (s *Server) RegisterService(sd *ServiceDesc, ss interface{})
RegisterService registers a service and its implementation to the HTTP server.
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) Use ¶
func (s *Server) Use(srv interface{}, m ...middleware.Middleware)
Use use a middleware to the transport.
type ServerDecodeRequestFunc ¶
ServerDecodeRequestFunc is decode request func.
type ServerEncodeErrorFunc ¶
type ServerEncodeErrorFunc func(err error, res http.ResponseWriter, req *http.Request)
ServerEncodeErrorFunc is encode error func.
type ServerEncodeResponseFunc ¶
type ServerEncodeResponseFunc func(out interface{}, res http.ResponseWriter, req *http.Request) error
ServerEncodeResponseFunc is encode response func.
type ServerInfo ¶
type ServerInfo struct { Request *http.Request Response http.ResponseWriter }
ServerInfo is HTTP server infomation.
func FromContext ¶
func FromContext(ctx context.Context) (s ServerInfo, ok bool)
FromContext returns the Transport value stored in ctx, if any.
type ServerOption ¶
type ServerOption func(*Server)
ServerOption is HTTP server option.
func ServerErrorEncoder ¶
func ServerErrorEncoder(fn ServerEncodeErrorFunc) ServerOption
ServerErrorEncoder with error handler option.
func ServerMiddleware ¶
func ServerMiddleware(m ...middleware.Middleware) ServerOption
ServerMiddleware with server middleware option.
func ServerRecoveryHandler ¶
func ServerRecoveryHandler(fn RecoveryHandlerFunc) ServerOption
ServerRecoveryHandler with recovery handler.
func ServerRequestDecoder ¶
func ServerRequestDecoder(fn ServerEncodeErrorFunc) ServerOption
ServerRequestDecoder with decode request option.
func ServerResponseEncoder ¶
func ServerResponseEncoder(fn ServerEncodeResponseFunc) ServerOption
ServerResponseEncoder with response handler option.
type ServiceDesc ¶
type ServiceDesc struct { ServiceName string HandlerType interface{} Methods []MethodDesc Metadata interface{} }
ServiceDesc represents a HTTP service's specification.
type ServiceRegistrar ¶
type ServiceRegistrar interface {
RegisterService(desc *ServiceDesc, impl interface{})
}
ServiceRegistrar wraps a single method that supports service registration.