socket

package
v1.9.0 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2022 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ClientRetry time.Duration = 20

	ErrorPrefix string = "ERROR_MSG::"
	ErrorRcpt   string = "ERROR_RCPT"

	ResponseTxt    string = "RESPONSE"
	ResponsePrefix string = ResponseTxt + "::"

	UpdateTxt    string = "UPDATE"
	UpdatePrefix string = UpdateTxt + "::"
)

Variables

This section is empty.

Functions

func MakeRequest

func MakeRequest[T any](c *Client, method, channel string, data any, timeout ...time.Duration) (value T, err error)

Types

type BaseData

type BaseData struct {
	Data []byte `json:"data"`
}

func (*BaseData) ParseData

func (b *BaseData) ParseData(v any) error

func (*BaseData) SetData

func (b *BaseData) SetData(v any) (err error)

type Client

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

func NewClient

func NewClient(opts ClientOptions) *Client

func (*Client) Auth

func (c *Client) Auth(subs ...ClientAuthSubscriber)

func (*Client) On

func (c *Client) On(method, channel string, handler ClientUpdateHandler)

func (*Client) Start

func (c *Client) Start(errChan ...chan error)

func (*Client) Stop

func (c *Client) Stop() (err error)

func (*Client) Update

func (c *Client) Update(subs ...ClientUpdateSubscriber)

type ClientAuthSubscriber

type ClientAuthSubscriber func(ref *ClientRef) (err error)

type ClientOptions

type ClientOptions struct {
	ServerHost string
	ServerPort string
	Name       string
	Alias      string
	TlsConfig  *tls.Config
}

type ClientRef

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

func (*ClientRef) ReadBytes

func (c *ClientRef) ReadBytes(delim byte) (value []byte, err error)

func (*ClientRef) ReadString

func (c *ClientRef) ReadString(delim byte) (value string, err error)

func (*ClientRef) Write

func (c *ClientRef) Write(b []byte) (i int, err error)

func (*ClientRef) WriteString

func (c *ClientRef) WriteString(d string) (int, error)

func (*ClientRef) WriteStringln

func (c *ClientRef) WriteStringln(d string) (int, error)

func (*ClientRef) Writeln

func (c *ClientRef) Writeln(b []byte) (int, error)

type ClientResponseCollection

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

func (*ClientResponseCollection) Get

func (c *ClientResponseCollection) Get(req *Request, timeout ...time.Duration) (out *Output, err error)

func (*ClientResponseCollection) Set

func (c *ClientResponseCollection) Set(uuid string, out *Output) (err error)

type ClientUpdateHandler added in v1.5.6

type ClientUpdateHandler func(out *Output)

type ClientUpdateHandlerCollection

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

func (*ClientUpdateHandlerCollection) On

func (c *ClientUpdateHandlerCollection) On(method, channel string, handler ClientUpdateHandler)

type ClientUpdateSubscriber

type ClientUpdateSubscriber func(collection *ClientUpdateHandlerCollection) (err error)

type Context

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

func (*Context) Error

func (c *Context) Error(v any, code ...int) *Output

func (*Context) ParseData

func (c *Context) ParseData(v any) error

func (*Context) Success

func (c *Context) Success(v any) *Output

func (*Context) Update

func (c *Context) Update(args ...any) error

func (*Context) UpdateAll

func (c *Context) UpdateAll(args ...any)

type Options

type Options interface {
	// contains filtered or unexported methods
}

type Output

type Output struct {
	BaseData

	Method  string `json:"method"`
	Channel string `json:"channel"`
	Code    int    `json:"code"`
	// contains filtered or unexported fields
}

func (Output) GetError added in v1.3.7

func (o Output) GetError() (err error)

type Request

type Request struct {
	BaseData

	UUID    string `json:"uuid" validator:"required"`
	Method  string `json:"method" validator:"required"`
	Channel string `json:"channel" validator:"required"`
}

type Server

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

func NewServer

func NewServer(opts ServerOptions) *Server

func (*Server) Auth

func (s *Server) Auth(subs ...ServerAuthSubscriber)

func (*Server) Boot

func (s *Server) Boot(subs ...ServerBootSubscriber)

func (*Server) Cleanup

func (s *Server) Cleanup(subs ...ServerCleanupSubscriber)

func (*Server) ClientInit

func (s *Server) ClientInit(handlers ...ServerClientInitHandler)

func (*Server) Handlers

func (s *Server) Handlers(subs ...ServerHandlerSubscriber)

func (*Server) IsListening

func (s *Server) IsListening() bool

func (*Server) Listen

func (s *Server) Listen(errChan ...chan error)

func (*Server) Setup

func (s *Server) Setup(subs ...ServerSetupSubscriber)

func (*Server) Stop

func (s *Server) Stop() error

func (*Server) UpdateAll

func (s *Server) UpdateAll(args ...any)

type ServerAuthSubscriber

type ServerAuthSubscriber func(ref *ServerClientRef) (err error)

type ServerBootSubscriber

type ServerBootSubscriber func() (err error)

type ServerCleanupSubscriber

type ServerCleanupSubscriber func(ref *ServerClientRef) (err error)

type ServerClientInitHandler

type ServerClientInitHandler func(updater *ServerClientUpdater) (err error)

type ServerClientInstance

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

func (*ServerClientInstance) Start

func (s *ServerClientInstance) Start()

func (*ServerClientInstance) Stop

func (s *ServerClientInstance) Stop()

func (*ServerClientInstance) Update

func (s *ServerClientInstance) Update(args ...any) (err error)

type ServerClientRef

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

func (*ServerClientRef) ReadBytes

func (s *ServerClientRef) ReadBytes(delim byte) ([]byte, error)

func (*ServerClientRef) ReadString

func (s *ServerClientRef) ReadString(delim byte) (string, error)

func (*ServerClientRef) Write

func (s *ServerClientRef) Write(b []byte) (int, error)

func (*ServerClientRef) WriteString

func (s *ServerClientRef) WriteString(d string) (int, error)

func (*ServerClientRef) WriteStringln

func (s *ServerClientRef) WriteStringln(d string) (int, error)

func (*ServerClientRef) Writeln

func (s *ServerClientRef) Writeln(b []byte) (int, error)

type ServerClientUpdater

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

func (*ServerClientUpdater) Update

func (s *ServerClientUpdater) Update(args ...any) (err error)

type ServerHandler

type ServerHandler func(ctx *Context) *Output

type ServerHandlerCollection

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

func (*ServerHandlerCollection) Get

func (s *ServerHandlerCollection) Get(method, channel string) (handler ServerHandler, err error)

func (*ServerHandlerCollection) Has

func (s *ServerHandlerCollection) Has(method, channel string) bool

func (*ServerHandlerCollection) Off

func (s *ServerHandlerCollection) Off(method, channel string)

func (*ServerHandlerCollection) On

func (s *ServerHandlerCollection) On(method, channel string, handler ServerHandler) (err error)

type ServerHandlerSubscriber

type ServerHandlerSubscriber func(subscriber *ServerHandlerCollection) (err error)

type ServerOptions

type ServerOptions struct {
	Host      string
	Port      string
	Name      string
	Alias     string
	TlsConfig *tls.Config
}

type ServerSetupSubscriber

type ServerSetupSubscriber func(ref *ServerClientRef) (err error)

Jump to

Keyboard shortcuts

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