web

package
v0.12.5 Latest Latest
Warning

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

Go to latest
Published: Jun 12, 2023 License: BSD-3-Clause Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WithHTTP

func WithHTTP() plugins.Plugin

WithHTTP launch of HTTP service with default Router

func WithHTTPClient

func WithHTTPClient() plugins.Plugin

WithHTTPClient init pool http clients

func WithHTTPDebug

func WithHTTPDebug() plugins.Plugin

WithHTTPDebug debug service over HTTP protocol with pprof enabled

func WithWebsocketClient

func WithWebsocketClient() plugins.Plugin

func WithWebsocketServer

func WithWebsocketServer(options ...WebsocketServerOption) plugins.Plugin

func WithWebsocketServerPool added in v0.12.4

func WithWebsocketServerPool(options ...WebsocketServerOption) plugins.Plugin

Types

type ClientHttp

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

type ConfigDebug

type ConfigDebug struct {
	Config webutil.ConfigHttp `yaml:"debug"`
}

ConfigDebug config to initialize HTTP debug service

func (*ConfigDebug) Default

func (v *ConfigDebug) Default()

type ConfigHttp

type ConfigHttp struct {
	Config map[string]webutil.ConfigHttp `yaml:"http"`
}

ConfigHttp config to initialize HTTP service

func (*ConfigHttp) Default

func (v *ConfigHttp) Default()

type Context

type Context interface {
	URL() *url.URL
	Redirect(uri string)
	Param(key string) Param
	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
	Log() log.WriterContext
	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)
}

RouteCollector interface of the router collection

type Router

type Router interface {
	Use(args ...Middleware)
	Collection(prefix string, args ...Middleware) RouteCollector
	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
	Get(name string) Router
}

RouterPool router pool handler

type WebsocketClient

type WebsocketClient interface {
	Create(ctx context.Context, url string, opts ...func(WebsocketClientOption)) (WebsocketClientConn, error)
}

type WebsocketClientConn

type WebsocketClientConn interface {
	ConnectID() string
	Event(call WebsocketClientHandler, eid ...uint)
	Encode(id uint, in interface{})
	Close()
	Run() error
}

type WebsocketClientHandler

type WebsocketClientHandler func(d WebsocketEventer, c WebsocketClientProcessor) error

type WebsocketClientOption

type WebsocketClientOption interface {
	Header(key string, value string)
}

type WebsocketClientProcessor

type WebsocketClientProcessor interface {
	ConnectID() string
	OnClose(cb func(cid string))
	Encode(eventID uint, in interface{})
	EncodeEvent(event WebsocketEventer, in interface{})
}

type WebsocketEventer

type WebsocketEventer interface {
	EventID() uint
	UniqueID() []byte
	Decode(in interface{}) error
}

type WebsocketServer

type WebsocketServer interface {
	Handling(ctx Context)
	Event(call WebsocketServerHandler, eid ...uint)
	Broadcast(t uint, m json.Marshaler)
	CloseAll()
	CountConn() int
}

type WebsocketServerHandler

type WebsocketServerHandler func(d WebsocketEventer, c WebsocketServerProcessor) error

type WebsocketServerOption

type WebsocketServerOption func(upg websocket.Upgrader)

func WebsocketServerOptionBuffer

func WebsocketServerOptionBuffer(read, write int) WebsocketServerOption

func WebsocketServerOptionCompression

func WebsocketServerOptionCompression(enable bool) WebsocketServerOption

type WebsocketServerPool added in v0.12.4

type WebsocketServerPool interface {
	Create(name string) WebsocketServer
}

type WebsocketServerProcessor

type WebsocketServerProcessor interface {
	ConnectID() string
	OnClose(cb func(cid string))
	OnOpen(cb func(cid string))
	Encode(eventID uint, in interface{})
	EncodeEvent(event WebsocketEventer, in interface{})
}

Jump to

Keyboard shortcuts

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