web

package
v2.1.7 Latest Latest
Warning

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

Go to latest
Published: Dec 21, 2024 License: BSD-3-Clause Imports: 28 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ErrorEncode

func ErrorEncode(w http.ResponseWriter, obj error)

func FormDataDecode

func FormDataDecode(r *http.Request, obj interface{}) error

func JSONDecode

func JSONDecode(r *http.Request, obj interface{}) error

func JSONEncode

func JSONEncode(w http.ResponseWriter, obj interface{})

func ParamFloat

func ParamFloat(r *http.Request, key string) (float64, error)

func ParamInt

func ParamInt(r *http.Request, key string) (int64, error)

func ParamString

func ParamString(r *http.Request, key string) (string, error)

func RawEncode

func RawEncode(w http.ResponseWriter, obj []byte)

func RecoveryMiddleware

func RecoveryMiddleware() func(
	func(http.ResponseWriter, *http.Request),
) func(http.ResponseWriter, *http.Request)

RecoveryMiddleware recovery go panic and write to log

func StreamEncode

func StreamEncode(w http.ResponseWriter, obj []byte, filename string)

func WithClient

func WithClient() plugins.Plugin

WithClient init pool http clients

func WithServer

func WithServer() plugins.Plugin

WithServer launch of HTTP service with default Router

func XMLDecode

func XMLDecode(r *http.Request, obj interface{}) error

func XMLEncode

func XMLEncode(w http.ResponseWriter, obj interface{})

Types

type BaseRouter

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

func NewBaseRouter

func NewBaseRouter() *BaseRouter

func (*BaseRouter) Global

func (v *BaseRouter) Global(
	middlewares ...func(func(http.ResponseWriter, *http.Request),
	) func(http.ResponseWriter, *http.Request))

Global add global middlewares

func (*BaseRouter) Middlewares

func (v *BaseRouter) Middlewares(
	path string, middlewares ...func(func(http.ResponseWriter, *http.Request),
	) func(http.ResponseWriter, *http.Request))

Middlewares add middlewares to route

func (*BaseRouter) NoFoundHandler

func (v *BaseRouter) NoFoundHandler(call func(http.ResponseWriter, *http.Request))

NoFoundHandler ctrlHandler call if route not found

func (*BaseRouter) Route

func (v *BaseRouter) Route(path string, ctrl func(http.ResponseWriter, *http.Request), methods ...string)

Route add new route

func (*BaseRouter) ServeHTTP

func (v *BaseRouter) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP http interface

type ClientHttp

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

func NewClientHttp

func NewClientHttp(opt ...ClientHttpOption) *ClientHttp

func (*ClientHttp) Call

func (v *ClientHttp) Call(ctx context.Context, method, uri string, in interface{}, out interface{}) error

type ClientHttpOption

type ClientHttpOption func(c *ClientHttp)

func ClientHttpOptionAuth

func ClientHttpOptionAuth(s signature.Storage) ClientHttpOption

func ClientHttpOptionCodec

func ClientHttpOptionCodec(
	enc func(in interface{}) (body []byte, contentType string, err error),
	dec func(code int, contentType string, body []byte, out interface{}) error,
) ClientHttpOption

func ClientHttpOptionCodecDefault

func ClientHttpOptionCodecDefault() ClientHttpOption

func ClientHttpOptionHeaders

func ClientHttpOptionHeaders(keyVal ...string) ClientHttpOption

func ClientHttpOptionSetup

func ClientHttpOptionSetup(proxy string, ttl time.Duration, countConn int) ClientHttpOption

type ClientHttpPool

type ClientHttpPool interface {
	Create(opts ...ClientHttpOption) *ClientHttp
}

type Config

type Config struct {
	Tag             string        `yaml:"tag"`
	Addr            string        `yaml:"addr"`
	Network         string        `yaml:"network,omitempty"`
	ReadTimeout     time.Duration `yaml:"read_timeout,omitempty"`
	WriteTimeout    time.Duration `yaml:"write_timeout,omitempty"`
	IdleTimeout     time.Duration `yaml:"idle_timeout,omitempty"`
	ShutdownTimeout time.Duration `yaml:"shutdown_timeout,omitempty"`
}

type ConfigHttpPool

type ConfigHttpPool struct {
	Config []Config `yaml:"http"`
}

ConfigHttpPool config to initialize HTTP service

func (*ConfigHttpPool) Default

func (v *ConfigHttpPool) Default()

type Context

type Context interface {
	URL() *url.URL
	Redirect(uri string)
	Param(key string) Param
	Query(key string) string
	Header() Header
	Cookie() Cookie

	BindBytes(in *[]byte) error
	BindJSON(in interface{}) error
	BindXML(in interface{}) error
	Error(code int, err error)
	ErrorJSON(code int, err error, ctx ErrCtx)
	Bytes(code int, b []byte)
	String(code int, b string, args ...interface{})
	JSON(code int, in interface{})
	Stream(code int, in []byte, filename string)

	Context() context.Context
	Request() *http.Request
	Response() http.ResponseWriter
}

Context request and response interface

type Cookie interface {
	Get(key string) *http.Cookie
	Set(value *http.Cookie)
}

type ErrCtx

type ErrCtx map[string]interface{}

func (ErrCtx) MarshalEasyJSON

func (v ErrCtx) MarshalEasyJSON(w *jwriter.Writer)

MarshalEasyJSON supports easyjson.Marshaler interface

func (ErrCtx) MarshalJSON

func (v ErrCtx) MarshalJSON() ([]byte, error)

MarshalJSON supports json.Marshaler interface

func (*ErrCtx) UnmarshalEasyJSON

func (v *ErrCtx) UnmarshalEasyJSON(l *jlexer.Lexer)

UnmarshalEasyJSON supports easyjson.Unmarshaler interface

func (*ErrCtx) UnmarshalJSON

func (v *ErrCtx) UnmarshalJSON(data []byte) error

UnmarshalJSON supports json.Unmarshaler interface

type Header interface {
	Get(key string) string
	Set(key, value string)
	Del(key string)
	Val(key string) string
	Copy()
}

type Middleware

type Middleware func(func(http.ResponseWriter, *http.Request)) func(http.ResponseWriter, *http.Request)

Middleware type of middleware

func ThrottlingMiddleware

func ThrottlingMiddleware(max int64) Middleware

ThrottlingMiddleware limits active requests

type Param

type Param interface {
	String() (string, error)
	Int() (int64, error)
	Float() (float64, error)
}

Param interface for typing a parameter from a URL

type RouteCollector

type RouteCollector interface {
	Get(path string, call func(ctx Context))
	Head(path string, call func(ctx Context))
	Post(path string, call func(ctx Context))
	Put(path string, call func(ctx Context))
	Delete(path string, call func(ctx Context))
	Options(path string, call func(ctx Context))
	Patch(path string, call func(ctx Context))
	Match(path string, call func(ctx Context), methods ...string)
	Collection(prefix string, args ...Middleware) RouteCollector
}

RouteCollector interface of the router collection

type Router

type Router interface {
	Use(args ...Middleware)
	NotFoundHandler(call func(ctx Context))
	RouteCollector
}

Router router handler interface

type RouterPool

type RouterPool interface {
	// All method to get all route handlers
	All(call func(name string, router Router))
	// Main method to get Main route handler
	Main() Router
	// Get method to get route handler by key
	Tag(name string) Router
}

RouterPool router pool handler

type Server

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

func NewServer

func NewServer(conf Config, handler http.Handler) *Server

NewServer create default http server

func (*Server) Down

func (v *Server) Down() error

Down stop http server

func (*Server) Up

func (v *Server) Up(ctx xc.Context) error

Up start http server

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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