http

package
v2.0.0-alpha.1 Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2021 License: MIT Imports: 25 Imported by: 1,742

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 BindForm

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

BindForm parses form parameters.

func BindVars

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

BindVars parses url parameters.

func Do

func Do(client *http.Client, req *http.Request, target interface{}) 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 NewClient

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

NewClient returns an 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 an http.RoundTripper.

func StatusError

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

StatusError converts error to status error.

func Vars

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

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

Types

type ClientInfo

type ClientInfo struct {
	Request *http.Request
}

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

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

DecodeRequestFunc deocder request func.

type EncodeErrorFunc

type EncodeErrorFunc func(res http.ResponseWriter, req *http.Request, err error)

EncodeErrorFunc is encode error func.

type EncodeResponseFunc

type EncodeResponseFunc func(res http.ResponseWriter, req *http.Request, v interface{}) error

EncodeResponseFunc is encode response func.

type MethodDesc

type MethodDesc struct {
	Path    string
	Method  string
	Handler methodHandler
}

MethodDesc represents a Proto service's method specification.

type RouteGroup

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

RouteGroup adds a matcher for the URL path and method. This matches if the given template is a prefix of the full URL path. See route.Path() for details on the tpl argument.

func (*RouteGroup) ANY

func (r *RouteGroup) ANY(path string, handler http.HandlerFunc)

ANY maps an HTTP Any request to the path and the specified handler.

func (*RouteGroup) DELETE

func (r *RouteGroup) DELETE(path string, handler http.HandlerFunc)

DELETE maps an HTTP Delete request to the path and the specified handler.

func (*RouteGroup) GET

func (r *RouteGroup) GET(path string, handler http.HandlerFunc)

GET maps an HTTP Get request to the path and the specified handler.

func (*RouteGroup) HEAD

func (r *RouteGroup) HEAD(path string, handler http.HandlerFunc)

HEAD maps an HTTP Head request to the path and the specified handler.

func (*RouteGroup) OPTIONS

func (r *RouteGroup) OPTIONS(path string, handler http.HandlerFunc)

OPTIONS maps an HTTP Options request to the path and the specified handler.

func (*RouteGroup) PATCH

func (r *RouteGroup) PATCH(path string, handler http.HandlerFunc)

PATCH maps an HTTP Patch request to the path and the specified handler.

func (*RouteGroup) POST

func (r *RouteGroup) POST(path string, handler http.HandlerFunc)

POST maps an HTTP Post request to the path and the specified handler.

func (*RouteGroup) PUT

func (r *RouteGroup) PUT(path string, handler http.HandlerFunc)

PUT maps an HTTP Put request to the path and the specified handler.

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

func (s *Server) RegisterService(desc *ServiceDesc, impl interface{})

RegisterService .

func (*Server) RouteGroup

func (s *Server) RouteGroup(prefix string) *RouteGroup

RouteGroup .

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 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.

type ServerOption

type ServerOption func(*Server)

ServerOption is HTTP server option.

func Address

func Address(addr string) ServerOption

Address with server address.

func ErrorEncoder

func ErrorEncoder(fn EncodeErrorFunc) ServerOption

ErrorEncoder with error handler option.

func Logger

func Logger(logger log.Logger) ServerOption

Logger with server logger.

func Middleware

func Middleware(m middleware.Middleware) ServerOption

Middleware with server middleware option.

func Network

func Network(network string) ServerOption

Network with server network.

func Timeout

func Timeout(timeout time.Duration) ServerOption

Timeout with server timeout.

type ServiceDesc

type ServiceDesc struct {
	ServiceName string
	Methods     []MethodDesc
	Metadata    interface{}
}

ServiceDesc represents a Proto 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