http

package
v2.0.0-rc2 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2021 License: MIT Imports: 26 Imported by: 1,765

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 CodecForRequest

func CodecForRequest(r *http.Request, name string) (encoding.Codec, bool)

CodecForRequest get encoding.Codec via http.Request

func CodecForResponse

func CodecForResponse(r *http.Response) encoding.Codec

CodecForResponse get encoding.Codec via http.Response

func DefaultErrorDecoder

func DefaultErrorDecoder(ctx context.Context, res *http.Response) error

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

func DefaultRequestDecoder(r *http.Request, v interface{}) error

DefaultRequestDecoder decodes the request body to object.

func DefaultRequestEncoder

func DefaultRequestEncoder(ctx context.Context, contentType string, in interface{}) ([]byte, error)

DefaultRequestEncoder is an HTTP request encoder.

func DefaultResponseDecoder

func DefaultResponseDecoder(ctx context.Context, res *http.Response, v interface{}) error

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 NewHandler

func NewHandler(handler interface{}, opts ...HandleOption) http.Handler

NewHandler new an HTTP handler.

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.

func Metadata

func Metadata(metatada metadata.Metadata) CallOption

Metadata is Metadata call option

func Method

func Method(method string) CallOption

Method is serviceMethod call option

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.

func (*Client) Do

func (client *Client) Do(req *http.Request, opts ...CallOption) (*http.Response, error)

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 (*Client) Invoke

func (client *Client) Invoke(ctx context.Context, method, path string, args interface{}, reply interface{}, opts ...CallOption) error

Invoke makes an rpc call procedure for remote service.

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 WithEndpoint

func WithEndpoint(endpoint string) ClientOption

WithEndpoint with client addr.

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 DecodeErrorFunc

type DecodeErrorFunc func(ctx context.Context, res *http.Response) error

DecodeErrorFunc is decode error func.

type DecodeRequestFunc

type DecodeRequestFunc func(*http.Request, interface{}) error

DecodeRequestFunc is decode request func.

type DecodeResponseFunc

type DecodeResponseFunc func(ctx context.Context, res *http.Response, out interface{}) error

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 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. Deprecated: use Handler instead.

func DefaultHandleOptions

func DefaultHandleOptions() HandleOptions

DefaultHandleOptions returns a default handle options. Deprecated: use NewHandler instead.

type Handler

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

Handler is handle options.

func (*Handler) ServeHTTP

func (h *Handler) ServeHTTP(w http.ResponseWriter, req *http.Request)

type MetadataCallOption

type MetadataCallOption struct {
	EmptyCallOption
	Metatada metadata.Metadata
}

MetadataCallOption is set Metadata for client call

type MethodCallOption

type MethodCallOption struct {
	EmptyCallOption
	Method string
}

MethodCallOption is set ServiceMethod for client call

type Server

type Server struct {
	*http.Server
	// contains filtered or unexported fields
}

Server is an HTTP server wrapper.

func NewServer

func NewServer(opts ...ServerOption) *Server

NewServer creates an HTTP server by options.

func (*Server) Endpoint

func (s *Server) Endpoint() (*url.URL, error)

Endpoint return a real address to registry endpoint. examples:

http://127.0.0.1:8000?isSecure=false

func (*Server) Handle

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

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

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

func (s *Server) HandlePrefix(prefix string, h http.Handler)

HandlePrefix registers a new route with a matcher for the URL path prefix.

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

func (s *Server) Start(ctx context.Context) error

Start start the HTTP server.

func (*Server) Stop

func (s *Server) Stop(ctx context.Context) error

Stop stop the HTTP server.

type ServerOption

type ServerOption func(*Server)

ServerOption is an HTTP server option.

func Address

func Address(addr string) ServerOption

Address with server address.

func Logger

func Logger(logger log.Logger) ServerOption

Logger with server logger.

func Network

func Network(network string) ServerOption

Network with server network.

func Timeout

func Timeout(timeout time.Duration) ServerOption

Timeout with server timeout.

type Target

type Target struct {
	Scheme    string
	Authority string
	Endpoint  string
}

Target is resolver target

type Transport

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

Transport is an HTTP transport.

func (*Transport) Endpoint

func (tr *Transport) Endpoint() string

Endpoint returns the transport endpoint.

func (*Transport) Kind

func (tr *Transport) Kind() string

Kind returns the transport kind.

func (*Transport) Metadata

func (tr *Transport) Metadata() metadata.Metadata

Metadata returns the transport metadata.

func (*Transport) Method

func (tr *Transport) Method() string

Method returns the transport method.

func (*Transport) SetMethod

func (tr *Transport) SetMethod(method string)

SetMethod sets the transport method.

func (*Transport) WithMetadata

func (tr *Transport) WithMetadata(md metadata.Metadata)

WithMetadata with a metadata into transport md.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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