Documentation ¶
Index ¶
- Constants
- func Do(client *http.Client, req *http.Request, target interface{}) error
- func NewClient(ctx context.Context, opts ...ClientOption) (*http.Client, error)
- func NewClientContext(ctx context.Context, info ClientInfo) context.Context
- func NewServerContext(ctx context.Context, info ServerInfo) context.Context
- func NewTransport(ctx context.Context, opts ...ClientOption) (http.RoundTripper, error)
- type ClientInfo
- type ClientOption
- type DecodeRequestFunc
- type EncodeErrorFunc
- type EncodeResponseFunc
- type HandleOption
- type HandleOptions
- type Server
- func (s *Server) Endpoint() (string, 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) ServeHTTP(res http.ResponseWriter, req *http.Request)
- func (s *Server) Start() error
- func (s *Server) Stop() error
- type ServerInfo
- type ServerOption
Constants ¶
const ( // SupportPackageIsVersion1 These constants should not be referenced from any other code. SupportPackageIsVersion1 = true )
Variables ¶
This section is empty.
Functions ¶
func Do ¶
Do send an HTTP request and decodes the body of response into target. returns an error (of type *Error) if the response status code is not 2xx.
func NewClientContext ¶
func NewClientContext(ctx context.Context, info ClientInfo) context.Context
NewClientContext returns a new Context that carries value.
func NewServerContext ¶
func NewServerContext(ctx context.Context, info ServerInfo) context.Context
NewServerContext returns a new Context that carries value.
func NewTransport ¶
func NewTransport(ctx context.Context, opts ...ClientOption) (http.RoundTripper, error)
NewTransport creates an http.RoundTripper.
Types ¶
type ClientInfo ¶
ClientInfo is HTTP client infomation.
func FromClientContext ¶
func FromClientContext(ctx context.Context) (info ClientInfo, ok bool)
FromClientContext returns the Transport value stored in ctx, if any.
type ClientOption ¶
type ClientOption func(*clientOptions)
ClientOption is HTTP client option.
func WithMiddleware ¶
func WithMiddleware(m middleware.Middleware) ClientOption
WithMiddleware with client middleware.
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 DecodeRequestFunc ¶
DecodeRequestFunc is decode request func.
type EncodeErrorFunc ¶
type EncodeErrorFunc func(http.ResponseWriter, *http.Request, error)
EncodeErrorFunc is encode error func.
type EncodeResponseFunc ¶
type EncodeResponseFunc func(http.ResponseWriter, *http.Request, interface{}) error
EncodeResponseFunc is encode response func.
type HandleOption ¶
type HandleOption func(*HandleOptions)
HandleOption is handle option.
func ErrorEncoder ¶
func ErrorEncoder(en EncodeErrorFunc) HandleOption
ErrorEncoder with error encoder.
func Middleware ¶
func Middleware(m middleware.Middleware) HandleOption
Middleware with middleware option.
func RequestDecoder ¶
func RequestDecoder(dec DecodeRequestFunc) HandleOption
RequestDecoder with request decoder.
func ResponseEncoder ¶
func ResponseEncoder(en EncodeResponseFunc) HandleOption
ResponseEncoder with response encoder.
type HandleOptions ¶
type HandleOptions struct { Decode DecodeRequestFunc Encode EncodeResponseFunc Error EncodeErrorFunc Middleware middleware.Middleware }
HandleOptions is handle options.
func DefaultHandleOptions ¶
func DefaultHandleOptions() HandleOptions
DefaultHandleOptions returns a default handle options.
type Server ¶
Server is a HTTP server wrapper.
func NewServer ¶
func NewServer(opts ...ServerOption) *Server
NewServer creates a 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.
type ServerInfo ¶
type ServerInfo struct { Request *http.Request Response http.ResponseWriter }
ServerInfo is HTTP server infomation.
func FromServerContext ¶
func FromServerContext(ctx context.Context) (info ServerInfo, ok bool)
FromServerContext returns the Transport value stored in ctx, if any.