http

package
v0.0.0-...-d3948d2 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2024 License: Apache-2.0 Imports: 18 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 CodecForRequest

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

CodecForRequest get encoding.Codec via http.Request

func DefaultErrorEncoder

func DefaultErrorEncoder(w http.ResponseWriter, r *http.Request, err 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 DefaultRequestQuery

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

DefaultRequestQuery decodes the request vars to object.

func DefaultRequestVars

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

DefaultRequestVars decodes the request vars to object.

func DefaultResponseEncoder

func DefaultResponseEncoder(w http.ResponseWriter, r *http.Request, v interface{}) error

DefaultResponseEncoder encodes the object to the HTTP response.

func RequestFromServerContext

func RequestFromServerContext(ctx context.Context) (*http.Request, bool)

RequestFromServerContext returns request from context.

func SetCookie

func SetCookie(ctx context.Context, cookie *http.Cookie)

SetCookie adds a Set-Cookie header to the provided ResponseWriter's headers. The provided cookie must have a valid Name. Invalid cookies may be silently dropped.

func SetOperation

func SetOperation(ctx context.Context, op string)

SetOperation sets the transport operation.

Types

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
	Middleware(middleware.Handler) middleware.Handler
	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)
}

Context is an HTTP Context.

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 FilterFunc

type FilterFunc func(http.Handler) http.Handler

FilterFunc is a function which receives a http.Handler and returns another http.Handler.

func FilterChain

func FilterChain(filters ...FilterFunc) FilterFunc

FilterChain returns a FilterFunc that specifies the chained handler for HTTP Router.

type Flusher

type Flusher = http.Flusher

Flusher type net/http

type HandlerFunc

type HandlerFunc func(Context) error

HandlerFunc defines a function to serve HTTP requests.

type Redirector

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

Redirector replies to the request with a redirect to url which may be a path relative to the request path.

type Request

type Request = http.Request

Request type net/http.

type ResponseWriter

type ResponseWriter = http.ResponseWriter

ResponseWriter type net/http.

type RouteInfo

type RouteInfo struct {
	Path   string
	Method string
}

RouteInfo is an HTTP route info.

type Router

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

Router is an HTTP router.

func (*Router) CONNECT

func (r *Router) CONNECT(path string, h HandlerFunc, m ...FilterFunc)

CONNECT registers a new CONNECT route for a path with matching handler in the router.

func (*Router) DELETE

func (r *Router) DELETE(path string, h HandlerFunc, m ...FilterFunc)

DELETE registers a new DELETE route for a path with matching handler in the router.

func (*Router) GET

func (r *Router) GET(path string, h HandlerFunc, m ...FilterFunc)

GET registers a new GET route for a path with matching handler in the router.

func (*Router) Group

func (r *Router) Group(prefix string, filters ...FilterFunc) *Router

Group returns a new router group.

func (*Router) HEAD

func (r *Router) HEAD(path string, h HandlerFunc, m ...FilterFunc)

HEAD registers a new HEAD route for a path with matching handler in the router.

func (*Router) Handle

func (r *Router) Handle(method, relativePath string, h HandlerFunc, filters ...FilterFunc)

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

func (*Router) OPTIONS

func (r *Router) OPTIONS(path string, h HandlerFunc, m ...FilterFunc)

OPTIONS registers a new OPTIONS route for a path with matching handler in the router.

func (*Router) PATCH

func (r *Router) PATCH(path string, h HandlerFunc, m ...FilterFunc)

PATCH registers a new PATCH route for a path with matching handler in the router.

func (*Router) POST

func (r *Router) POST(path string, h HandlerFunc, m ...FilterFunc)

POST registers a new POST route for a path with matching handler in the router.

func (*Router) PUT

func (r *Router) PUT(path string, h HandlerFunc, m ...FilterFunc)

PUT registers a new PUT route for a path with matching handler in the router.

func (*Router) TRACE

func (r *Router) TRACE(path string, h HandlerFunc, m ...FilterFunc)

TRACE registers a new TRACE route for a path with matching handler in the router.

type Server

type Server struct {
	// 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) 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) HandleHeader

func (s *Server) HandleHeader(key, val string, h http.HandlerFunc)

HandleHeader registers a new route with a matcher for the header.

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

func (s *Server) Route(prefix string, filters ...FilterFunc) *Router

Route registers an HTTP router.

func (*Server) Router

func (s *Server) Router() *mux.Router

func (*Server) Use

func (s *Server) Use(selector string, m ...middleware.Middleware)

Use uses a service middleware with selector. selector:

  • '/*'
  • '/helloworld.v1.Greeter/*'
  • '/helloworld.v1.Greeter/SayHello'

func (*Server) WalkRoute

func (s *Server) WalkRoute(fn WalkRouteFunc) error

WalkRoute walks the router and all its sub-routers, calling walkFn for each route in the tree.

type ServerOption

type ServerOption func(*Server)

ServerOption is an HTTP server option.

func ErrorEncoder

func ErrorEncoder(en EncodeErrorFunc) ServerOption

ErrorEncoder with error encoder.

func Filter

func Filter(filters ...FilterFunc) ServerOption

Filter with HTTP middleware option.

func MethodNotAllowedHandler

func MethodNotAllowedHandler(handler http.Handler) ServerOption

func Middleware

func Middleware(m ...middleware.Middleware) ServerOption

Middleware with service middleware option.

func NotFoundHandler

func NotFoundHandler(handler http.Handler) ServerOption

func PathPrefix

func PathPrefix(prefix string) ServerOption

PathPrefix with mux's PathPrefix, router will be replaced by a subrouter that start with prefix.

func RequestDecoder

func RequestDecoder(dec DecodeRequestFunc) ServerOption

RequestDecoder with request decoder.

func RequestQueryDecoder

func RequestQueryDecoder(dec DecodeRequestFunc) ServerOption

RequestQueryDecoder with request decoder.

func RequestVarsDecoder

func RequestVarsDecoder(dec DecodeRequestFunc) ServerOption

RequestVarsDecoder with request decoder.

func ResponseEncoder

func ResponseEncoder(en EncodeResponseFunc) ServerOption

ResponseEncoder with response encoder.

func StrictSlash

func StrictSlash(strictSlash bool) ServerOption

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

func Timeout

func Timeout(timeout time.Duration) ServerOption

Timeout with server timeout.

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() transport.Kind

Kind returns the transport kind.

func (*Transport) Operation

func (tr *Transport) Operation() string

Operation returns the transport operation.

func (*Transport) PathTemplate

func (tr *Transport) PathTemplate() string

PathTemplate returns the http path template.

func (*Transport) ReplyHeader

func (tr *Transport) ReplyHeader() transport.Header

ReplyHeader returns the reply header.

func (*Transport) Request

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

Request returns the HTTP request.

func (*Transport) RequestHeader

func (tr *Transport) RequestHeader() transport.Header

RequestHeader returns the request header.

type Transporter

type Transporter interface {
	transport.Transporter
	Request() *http.Request
	PathTemplate() string
}

Transporter is http Transporter

type WalkRouteFunc

type WalkRouteFunc func(RouteInfo) error

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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