http

package
v0.1.0-alpha3 Latest Latest
Warning

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

Go to latest
Published: May 18, 2021 License: MIT Imports: 21 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 Do

func Do(client *http.Client, req *http.Request, target interface{}) error

Do send a 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 NewClient

func NewClient(ctx context.Context, opts ...ClientOption) (*http.Client, error)

NewClient returns a HTTP client.

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 a http.RoundTripper.

Types

type ClientInfo

type ClientInfo struct {
	Request *http.Request
}

ClientInfo represent HTTP client information.

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(o *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 DecodeErrorFunc

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

DecodeErrorFunc is decode error func.

type DecodeRequestFunc

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

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

type Server struct {
	*http.Server
	// 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) Endpoint

func (s *Server) Endpoint() (string, 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() error

Start start the HTTP server.

func (*Server) Stop

func (s *Server) Stop() error

Stop stop the HTTP server.

type ServerInfo

type ServerInfo struct {
	Request  *http.Request
	Response http.ResponseWriter
}

ServerInfo represent HTTP server information.

func FromServerContext

func FromServerContext(ctx context.Context) (info ServerInfo, ok bool)

FromServerContext returns the Transport value stored in ctx, if any.

type ServerOption

type ServerOption func(*Server)

ServerOption is HTTP server option.

func Address

func Address(addr string) ServerOption

Address with server address.

func Logger

func Logger(name string) 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.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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