httpx

package
v0.0.0-...-fc59d6d Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2024 License: MIT Imports: 26 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultRequestEncoder

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

func DefaultResponseDecoder

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

DefaultResponseDecoder is an HTTP response decoder.

func EncodeURL

func EncodeURL(pathTemplate string, msg interface{}, needQuery bool) string

EncodeURL encode proto message to url path.

func GetTransportFromRequest

func GetTransportFromRequest(r *http.Request) transport.ITransport

func SetOperation

func SetOperation(ctx context.Context, op string)

SetOperation sets the transport Operation.

Types

type CallOption

type CallOption func(*callInfo)

func AddRequestHeader

func AddRequestHeader(key, value string) CallOption

func OnResponse

func OnResponse(onResponse func(*http.Response) error) CallOption

func Operation

func Operation(operation string) CallOption

func PathTemplate

func PathTemplate(pattern string) CallOption

PathTemplate is http path template

func RequestHeader

func RequestHeader(header http.Header) CallOption

func SetRequestContentType

func SetRequestContentType(contentType string) CallOption

SetRequestContentType with request content type.

type Client

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

Client is an HTTP client.

func NewClient

func NewClient(opts ...ClientOption) (*Client, error)

NewClient returns an HTTP client.

func (*Client) Close

func (client *Client) Close() error

Close tears down the Transport and all underlying connections.

func (*Client) Do

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

func (*Client) Invoke

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

Invoke makes a rpc call procedure for remote service.

type ClientOption

type ClientOption func(*Client)

ClientOption is HTTP client option.

func WithEndpoint

func WithEndpoint(endpoint string) ClientOption

WithEndpoint with client addr.

func WithMiddlewares

func WithMiddlewares(m ...middleware.Middleware) ClientOption

WithMiddlewares 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 WithTLSConfig

func WithTLSConfig(c *tls.Config) ClientOption

WithTLSConfig with tls config.

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 Context

type Context interface {
	context.Context
	Vars() url.Values
	Query() url.Values
	Form() url.Values
	Header() http.Header
	Request() *http.Request
	Response() http.ResponseWriter
	Bind(interface{}) error
	BindVars(interface{}) error
	BindQuery(interface{}) error
	BindForm(interface{}) error
	Returns(interface{}, error) error
	Result(int, interface{}) error
	JSON(int, interface{}) error
	XML(int, interface{}) error
	String(int, string) error
	Blob(int, string, []byte) error
	Stream(int, string, io.Reader) error
	Reset(http.ResponseWriter, *http.Request)
	ReturnError(error)
}

Context is an HTTP Context.

func NewCtx

func NewCtx(rsp http.ResponseWriter, req *http.Request) Context

type DecodeResponseFunc

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

DecodeResponseFunc is response decode func.

type EncodeRequestFunc

type EncodeRequestFunc func(ctx context.Context, contentType string, in interface{}) (body []byte, err error)

EncodeRequestFunc is request encode func.

type ErrorEncoder

type ErrorEncoder func(http.ResponseWriter, *http.Request, error)

ErrorEncoder is encode error func.

type IHttpRouter

type IHttpRouter interface {
	ServeHTTP(res http.ResponseWriter, req *http.Request)
	Use(mws ...middleware.HttpMiddleware)
	Group(prefix string, middlewares ...middleware.HttpMiddleware) *Router
	Handle(path string, h http.Handler)
	HandlePrefix(prefix string, h http.Handler)
	HandleFunc(path string, h http.HandlerFunc)
	HandleHeader(h http.HandlerFunc, headerPairs ...string)
}

type IRedirect

type IRedirect interface {
	Redirect() (string, int)
}

func NewRedirect

func NewRedirect(url string, code int) IRedirect

NewRedirect new a redirect with url, which may be a path relative to the request path. The provided code should be in the 3xx range and is usually StatusMovedPermanently, StatusFound or StatusSeeOther. If the Content-Type header has not been set, Redirect sets it to "text/html; charset=utf-8" and writes a small HTML body. Setting the Content-Type header to any value, including nil, disables that behavior.

type IRouter

type IRouter interface {
	IHttpRouter
	IRouteMethod
	WalkRoute(fn WalkRouteFunc) error
}

type IRouterCoder

type IRouterCoder interface {
	BindVars() RequestDecoder
	BindQuery() RequestDecoder
	BindForm() RequestDecoder
	BindBody() RequestDecoder
	ResponseEncoder() ResponseEncoder
	ErrorEncoder() ErrorEncoder
}

type IRouterSetting

type IRouterSetting interface {
	UseEncodedPath() bool
	SetUseEncodedPath(bool)
	StrictSlash() bool
	SetStrictSlash(bool)
	SkipClean() bool
	SetSkipClean(bool)
	Prefix() string
	SetPrefix(string)
	NotFoundHandler() http.Handler
	SetNotFoundHandler(handler http.Handler)
	NotAllowedHandler() http.Handler
	SetNotAllowedHandler(handler http.Handler)
}

type RequestDecoder

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

RequestDecoder is decode request func.

type ResponseEncoder

type ResponseEncoder func(int, http.ResponseWriter, *http.Request, interface{}) error

ResponseEncoder is encode response func.

type RouteInfo

type RouteInfo struct {
	Path   string
	Method string
}

RouteInfo is an HTTP route info.

type Router

type Router struct {
	*RouterCfg
	// contains filtered or unexported fields
}

Router is an HTTP coder.

func (*Router) CONNECT

func (r *Router) CONNECT(path string, h http.HandlerFunc, m ...middleware.HttpMiddleware)

func (*Router) DELETE

func (r *Router) DELETE(path string, h http.HandlerFunc, m ...middleware.HttpMiddleware)

func (*Router) GET

func (r *Router) GET(path string, h http.HandlerFunc, m ...middleware.HttpMiddleware)

func (*Router) Group

func (r *Router) Group(prefix string, middlewares ...middleware.HttpMiddleware) *Router

func (*Router) HEAD

func (r *Router) HEAD(path string, h http.HandlerFunc, m ...middleware.HttpMiddleware)

func (*Router) Handle

func (r *Router) Handle(path string, h http.Handler)

func (*Router) HandleFunc

func (r *Router) HandleFunc(path string, h http.HandlerFunc)

func (*Router) HandleHeader

func (r *Router) HandleHeader(h http.HandlerFunc, headerPairs ...string)

func (*Router) HandlePrefix

func (r *Router) HandlePrefix(prefix string, h http.Handler)

func (*Router) OPTIONS

func (r *Router) OPTIONS(path string, h http.HandlerFunc, m ...middleware.HttpMiddleware)

func (*Router) PATCH

func (r *Router) PATCH(path string, h http.HandlerFunc, m ...middleware.HttpMiddleware)

func (*Router) POST

func (r *Router) POST(path string, h http.HandlerFunc, m ...middleware.HttpMiddleware)

func (*Router) PUT

func (r *Router) PUT(path string, h http.HandlerFunc, m ...middleware.HttpMiddleware)

func (*Router) ServeHTTP

func (r *Router) ServeHTTP(res http.ResponseWriter, req *http.Request)

func (*Router) TRACE

func (r *Router) TRACE(path string, h http.HandlerFunc, m ...middleware.HttpMiddleware)

func (*Router) Use

func (r *Router) Use(mws ...middleware.HttpMiddleware)

func (*Router) WalkRoute

func (r *Router) WalkRoute(fn WalkRouteFunc) error

type RouterCfg

type RouterCfg struct {
	// If true, "/path/foo%2Fbar/to" will match the path "/path/{var}/to"
	UseEncodedPath bool

	// If true, when the path pattern is "/path/", accessing "/path" will
	// redirect to the former and vice versa.
	StrictSlash bool

	// If true, when the path pattern is "/path//to", accessing "/path//to"
	// will not redirect
	SkipClean bool

	// Configurable Handler to be used when no route matches.
	NotFoundHandler http.Handler

	// Configurable Handler to be used when the request method does not match the route.
	MethodNotAllowedHandler http.Handler

	RootPrefix string

	Coder IRouterCoder
}

func NewRouterCfg

func NewRouterCfg() *RouterCfg

type Server

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

Server is an HTTP server wrappedCtx.

func NewServer

func NewServer(opts ...ServerOption) *Server

func (*Server) Endpoint

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

func (*Server) GetRouter

func (s *Server) GetRouter() IRouter

func (*Server) Middlewares

func (s *Server) Middlewares() []middleware.Middleware

func (*Server) NewRouteGroup

func (s *Server) NewRouteGroup(prefix string, httpMiddlewares ...middleware.HttpMiddleware) *Router

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

func (s *Server) SetMiddlewares(mws ...middleware.Middleware)

func (*Server) Start

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

Start the HTTP server.

func (*Server) Stop

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

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 Endpoint

func Endpoint(endpoint *url.URL) ServerOption

Endpoint with server address.

func Listener

func Listener(lis net.Listener) ServerOption

Listener with server listener.

func Network

func Network(network string) ServerOption

Network with server network.

func RouterCoder

func RouterCoder(coder IRouterCoder) ServerOption

RouterCoder

func RouterMethodNotAllowedHandler

func RouterMethodNotAllowedHandler(handler http.Handler) ServerOption

RouterMethodNotAllowedHandler

func RouterNotFoundHandler

func RouterNotFoundHandler(handler http.Handler) ServerOption

RouterNotFoundHandler

func RouterPathPrefix

func RouterPathPrefix(prefix string) ServerOption

RouterPathPrefix with mux's PathPrefix, coder will replace by a subrouter that start with RootPrefix.

func RouterSkipClean

func RouterSkipClean(skipClean bool) ServerOption

RouterSkipClean with mux's SkipClean

func RouterStrictSlash

func RouterStrictSlash(strictSlash bool) ServerOption

RouterStrictSlash with mux's StrictSlash If true, when the path pattern is "/path/", accessing "/path" will redirect to the former and vice versa.

func RouterUseEncodedPath

func RouterUseEncodedPath() ServerOption

RouterUseEncodedPath with mux's SkipClean

func SetMiddlewares

func SetMiddlewares(mws ...middleware.Middleware) ServerOption

SetMiddlewares with server middlewares.

func TLSConfig

func TLSConfig(c *tls.Config) ServerOption

TLSConfig with TLS config.

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 {
	transport.BaseTransport
	Request *http.Request
}

func (*Transport) GetKind

func (tr *Transport) GetKind() transport.Kind

func (*Transport) GetRequest

func (tr *Transport) GetRequest() *http.Request

type WalkRouteFunc

type WalkRouteFunc func(RouteInfo) error

WalkRouteFunc is the type of the function called for each route visited by Walk.

Directories

Path Synopsis
proto
Package proto defines the protobuf Coder.
Package proto defines the protobuf Coder.
xml

Jump to

Keyboard shortcuts

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