webutil

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2023 License: BSD-3-Clause Imports: 24 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ErrorEncode

func ErrorEncode(w http.ResponseWriter, v error)

func JSONDecode

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

func JSONEncode

func JSONEncode(w http.ResponseWriter, v 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, v []byte)

func RecoveryMiddleware

func RecoveryMiddleware(l log.Logger) 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, v []byte, filename string)

func XMLDecode

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

func XMLEncode

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

Types

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 ConfigEpoll

type ConfigEpoll struct {
	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 ConfigHttp

type ConfigHttp struct {
	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 EpollHandler

type EpollHandler func([]byte, io.Writer) error

type Router

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

Router model

func NewRouter

func NewRouter() *Router

NewRouter init new router

func (*Router) Global

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

Global add global middlewares

func (*Router) Middlewares

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

Middlewares add middlewares to route

func (*Router) NoFoundHandler

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

NoFoundHandler ctrlHandler call if route not found

func (*Router) Route

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

Route add new route

func (*Router) ServeHTTP

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

ServeHTTP http interface

type ServerDebug

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

ServerDebug service model

func NewServerDebug

func NewServerDebug(c ConfigHttp, l log.Logger) *ServerDebug

NewServerDebug init debug service

func (*ServerDebug) Down

func (o *ServerDebug) Down() error

Down stop service

func (*ServerDebug) Up

func (o *ServerDebug) Up(ctx app.Context) error

Up start service

type ServerEpoll

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

func NewServerEpoll

func NewServerEpoll(conf ConfigEpoll, handler EpollHandler, eof []byte, l log.Logger) *ServerEpoll

func (*ServerEpoll) Down

func (s *ServerEpoll) Down() error

Down ...

func (*ServerEpoll) Up

func (s *ServerEpoll) Up(ctx app.Context) (err error)

Up ...

type ServerHttp

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

func NewServerHttp

func NewServerHttp(conf ConfigHttp, handler http.Handler, l log.Logger) *ServerHttp

NewServerHttp create default http server

func (*ServerHttp) Down

func (s *ServerHttp) Down() error

Down stop http server

func (*ServerHttp) Up

func (s *ServerHttp) Up(ctx application.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