websvc

package module
v0.0.15 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2024 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoPrivilege = errors.New("fobidden")
)

Functions

func Auth

func Auth[TSES interface{}](cfg *AuthenticatorConfigure, handler func(*gin.Context, TSES) (int, interface{}, error), privilege string) gin.HandlerFunc

func AuthD

func AuthD[TSES interface{}, TDATA interface{}](cfg *AuthenticatorConfigure, handler func(*gin.Context, TSES, TDATA) (int, interface{}, error), privilege string) gin.HandlerFunc

func AuthN added in v0.0.5

func AuthN[TSES interface{}](cfg *AuthenticatorConfigure, handler func(*gin.Context, TSES) (int, interface{}, error), privilege string) gin.HandlerFunc

func AuthQ

func AuthQ[TSES interface{}](cfg *AuthenticatorConfigure, handler func(*gin.Context, TSES, map[string]string) (int, interface{}, error), privilege string) gin.HandlerFunc

func AuthQD

func AuthQD[TSES interface{}, TDATA interface{}](cfg *AuthenticatorConfigure, handler func(*gin.Context, TSES, map[string]string, TDATA) (int, interface{}, error), privilege string) gin.HandlerFunc

func AuthQN added in v0.0.5

func AuthQN[TSES interface{}](cfg *AuthenticatorConfigure, handler func(*gin.Context, TSES, map[string]string) (int, interface{}, error), privilege string) gin.HandlerFunc

func Handler added in v0.0.2

func Handler(handler func(*gin.Context) (int, interface{}, error)) gin.HandlerFunc

func HandlerD added in v0.0.2

func HandlerD[TDATA interface{}](handler func(*gin.Context, TDATA) (int, interface{}, error)) gin.HandlerFunc

func HandlerQ added in v0.0.2

func HandlerQ(handler func(*gin.Context, map[string]string) (int, interface{}, error)) gin.HandlerFunc

func HandlerQD added in v0.0.2

func HandlerQD[TDATA interface{}](handler func(*gin.Context, map[string]string, TDATA) (int, interface{}, error)) gin.HandlerFunc

func HttpTask added in v0.0.6

func HttpTask(name, addr string, initializer func(*gin.Engine)) service.ServiceTask

func HttpsTask added in v0.0.6

func HttpsTask(name, addr, certFile, keyFile string, initializer func(*gin.Engine)) service.ServiceTask

func NewConnectionPool added in v0.0.9

func NewConnectionPool() *sync.Pool

func NewHandler added in v0.0.6

func NewHandler(initializer func(*gin.Engine)) http.Handler

func Task

func Task(name string, config *Config, initializer func(*gin.Engine)) service.ServiceTask

func WebSocketHandler added in v0.0.9

func WebSocketHandler(cfg *WebSocketConfig) gin.HandlerFunc

func WebSocketTask added in v0.0.10

func WebSocketTask(url string, cfg *WebSocketConfig) service.ServiceTask

Types

type AuthenticatorConfigure

type AuthenticatorConfigure struct {
	QueryToken     func(context.Context, string) (interface{}, string, error)
	CheckPrivilege func(context.Context, string, interface{}, string) error
	RefreshToken   func(context.Context, string, interface{}) error
	SuperPrivilege string
	TsTolerance    int64
}

type Config added in v0.0.7

type Config struct {
	Host    string `mapstructure:"host"`     // [Optional] Listen host, default is all interfaces
	Port    int    `mapstructure:"port"`     // [Optional] Listen port, default is 80 if SSL is not enabled, 443 otherwise
	SSLCert string `mapstructure:"ssl_cert"` // [Optional] SSL Certificate file path
	SSLKey  string `mapstructure:"ssl_key"`  // [Optional] SSL Key file path
}

func (*Config) IsSSL added in v0.0.8

func (c *Config) IsSSL() bool

type Response

type Response struct {
	ContentType string
	Body        []byte
}

type WebSocketConfig added in v0.0.14

type WebSocketConfig struct {

	// [Optional] Used to get the headers for the websocket connection
	// client side only
	Headers func(attachment interface{}) http.Header

	// [Optional] Used to do before upgrade operations, such as authentication
	// If the upgrade is allowed, return 0, <attachment>, nil, the <attachment> will be set to the Attachment of the connection object
	// If the upgrade is not allowed, the return data will be processed as response.
	BeforeUpgrade func(ctx *gin.Context, attachment interface{}) (int, interface{}, error)

	// [Optional] Connected event processor
	// Initialize logic data for the connection
	OnConnected func(conn *WebSocketConnection, attachment interface{})

	// [Optional] Disconnected event processor
	OnDisconnected func(conn *WebSocketConnection, attachment interface{})

	OnMessage func(conn *WebSocketConnection, msgType int, msg *misc.Buffer, attachment interface{})

	// [Optional] The connection pool for websocket connections
	// A connection poll could be created by NewConnectionPool() function
	// If specified, the connections will be pooled and reused, this will improve performance but may need more memory
	// If set to nil, the connections will not be pooled, this will reduce memory usage but may decrease performance
	ConnectionPool *sync.Pool

	// [Optional] The buffer pool for websocket connections
	// A buffer pool could be created by misc.NewBufferPool() function
	// If specified, the buffers will be pooled and reused, this will improve performance but may need more memory
	// If set to nil, the buffers will not be pooled, this will reduce memory usage but may decrease performance
	BufferPool *misc.BufferPool

	// [Optional] The buffer size for websocket connections
	// If BufferPool is nil, this value must be specified and will be used to create a buffer pool
	BufferSize uint

	// [Optional] The heartbeat interval in seconds
	// If set to 0, the default value 10s will be used
	// Heartbeat will be triggered by the client side
	BeatInterval int

	// [Optional] The heartbeat timeout in seconds
	// If set to 0, the heartbeat timeout will be set to BeatInterval * 3
	BeatTimeout int

	// [Optional] The reconnect interval in seconds, client side only
	// If set to 0, the default value 5s will be used
	ReconnectInterval int

	// User-defined attachment
	// The attachment will be passed to all handle functions in this config
	Attachment interface{}
}

type WebSocketConnection added in v0.0.9

type WebSocketConnection struct {
	Attachment interface{}
	// contains filtered or unexported fields
}

func NewWebSocketConnection added in v0.0.9

func NewWebSocketConnection(cfg *WebSocketConfig) *WebSocketConnection

func (*WebSocketConnection) AddRef added in v0.0.9

func (*WebSocketConnection) Close added in v0.0.9

func (sc *WebSocketConnection) Close()

func (*WebSocketConnection) Connect added in v0.0.10

func (sc *WebSocketConnection) Connect(url string, qs chan os.Signal) bool

func (*WebSocketConnection) Release added in v0.0.9

func (sc *WebSocketConnection) Release()

func (*WebSocketConnection) Send added in v0.0.10

func (sc *WebSocketConnection) Send(msg *misc.Buffer)

func (*WebSocketConnection) SendBinaryBuffer added in v0.0.11

func (sc *WebSocketConnection) SendBinaryBuffer(msg *misc.Buffer)

func (*WebSocketConnection) SendBytes added in v0.0.11

func (sc *WebSocketConnection) SendBytes(data []byte)

func (*WebSocketConnection) SendText added in v0.0.11

func (sc *WebSocketConnection) SendText(msg string)

func (*WebSocketConnection) SendTextBuffer added in v0.0.11

func (sc *WebSocketConnection) SendTextBuffer(msg *misc.Buffer)

Jump to

Keyboard shortcuts

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