http

package
v0.0.0-...-8a93dc7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 28, 2021 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const SupportPackageIsVersion1 = true

SupportPackageIsVersion1 These constants should not be referenced from any other code.

Variables

This section is empty.

Functions

func CheckResponse

func CheckResponse(res *http.Response) error

CheckResponse returns an error (of type *Error) if the response status code is not 2xx.

func DecodeResponse

func DecodeResponse(res *http.Response, v interface{}) error

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

func DefaultRecoveryHandler(ctx context.Context, req, err interface{}) error

DefaultRecoveryHandler is default recovery handler.

func DefaultRequestDecoder

func DefaultRequestDecoder(in interface{}, req *http.Request) error

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

func PopulateBody(msg proto.Message, req *http.Request) error

PopulateBody parses body payload.

func PopulateForm

func PopulateForm(msg proto.Message, req *http.Request) error

PopulateForm parses query parameters

func PopulateVars

func PopulateVars(msg proto.Message, req *http.Request) error

PopulateVars parses url parameters.

func RequestCodec

func RequestCodec(req *http.Request) (encoding.Codec, error)

RequestCodec returns request codec.

func ResponseCodec

func ResponseCodec(req *http.Request) (string, encoding.Codec, error)

ResponseCodec returns response codec.

func StatusError

func StatusError(err error) (int, *errors.StatusError)

StatusError converts error to http error.

func Vars

func Vars(req *http.Request) map[string]string

Vars returns the route variables for the current request, if any.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client is a HTTP transport client.

func (*Client) RoundTrip

func (c *Client) RoundTrip(req *http.Request) (res *http.Response, err error)

RoundTrip is transport round trip.

type ClientDecodeErrorFunc

type ClientDecodeErrorFunc func(res *http.Response) error

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

type MethodDesc struct {
	Path    string
	Method  string
	Handler serverMethodHandler
}

MethodDesc represents a HTTP service's method specification.

type RecoveryHandlerFunc

type RecoveryHandlerFunc func(ctx context.Context, req, err interface{}) error

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) Handle

func (s *Server) Handle(path string, handler http.Handler)

Handle registers a new route with a matcher for the URL path.

func (*Server) HandleFunc

func (s *Server) HandleFunc(path string, h func(http.ResponseWriter, *http.Request))

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

type ServerDecodeRequestFunc func(in interface{}, req *http.Request) error

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL