cyb

package
v1.6.2 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2024 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MakeRequest

func MakeRequest[T any](client *Client, method, channel string, data any) (value T, err error)

Types

type AuthCallback

type AuthCallback func(conn Connection) (err error)

type BootCallback

type BootCallback func() (err error)

type ChannelData

type ChannelData struct {
	Method  string `json:"method"`
	Channel string `json:"channel"`
}

type Client

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

func (*Client) Auth

func (x *Client) Auth(callbacks ...AuthCallback)

func (*Client) Boot

func (x *Client) Boot(callbacks ...BootCallback)

func (*Client) Connect

func (x *Client) Connect(opts *Options) (errChan chan error)

func (*Client) On

func (x *Client) On(method, channel string, handler UpdateHandler)

func (*Client) Request

func (x *Client) Request(method, channel string, data any) (value Data, err error)

func (*Client) Run

func (x *Client) Run() (err error)

func (*Client) SetRequestTimeout

func (x *Client) SetRequestTimeout(timeout int)

Set Timeout for requests (in seconds). Defaults to 30 seconds

func (*Client) Start

func (x *Client) Start(opts *Options) chan error

func (*Client) Stop

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

func (*Client) Updates

func (x *Client) Updates(callbacks ...UpdateRouterCallback)

type ClientInitCallback

type ClientInitCallback func(i InboundConnection) (err error)

type ClientUpdateRouter

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

func (*ClientUpdateRouter) Clear

func (x *ClientUpdateRouter) Clear(method, channel string)

func (*ClientUpdateRouter) On

func (x *ClientUpdateRouter) On(method, channel string, handler UpdateHandler)

func (*ClientUpdateRouter) Send

func (x *ClientUpdateRouter) Send(method, channel string, data Data)

type Connection

type Connection interface {
	ReadBytes(delim byte) (b []byte, err error)
	ReadLine() (b []byte, err error)
	ReadString(delim byte) (s string, err error)
	ReadStringLine() (s string, err error)

	Write(p []byte) (n int, err error)
	WriteLine(p []byte) (n int, err error)
	WriteString(s string) (n int, err error)
	WriteStringLine(s string) (n int, err error)
}

type Context

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

func (Context) Bind

func (x Context) Bind(v any) (err error)

func (*Context) Data

func (x *Context) Data(v any, code ...int) Output

func (*Context) Error

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

func (*Context) Update

func (x *Context) Update(v any, code ...int) (err error)

func (*Context) UpdateAll

func (x *Context) UpdateAll(v any, code ...int) (err error)

type Data

type Data struct {
	Code    int    `json:"code"`
	Content []byte `json:"content"`
}

func (Data) Bind

func (x Data) Bind(v any) (err error)

func (Data) GetCode

func (x Data) GetCode() int

func (Data) GetContent

func (x Data) GetContent() any

func (Data) IsError

func (x Data) IsError() bool

func (*Data) SetContent

func (x *Data) SetContent(v any) (err error)

type Error

type Error struct {
	ChannelData
	UUID    string `json:"uuid"`
	Code    int    `json:"code"`
	Message string `json:"message"`
}

func (Error) Error

func (x Error) Error() (err error)

func (Error) GetCode

func (x Error) GetCode() int

func (Error) GetContent

func (x Error) GetContent() any

func (Error) ToData

func (x Error) ToData() (data Data)

type Inbound

type Inbound struct {
	Info
	// contains filtered or unexported fields
}

func (*Inbound) Run

func (x *Inbound) Run()

func (*Inbound) Update

func (x *Inbound) Update(method, channel string, v any, code ...int) (err error)

func (*Inbound) UpdateAll

func (x *Inbound) UpdateAll(method, channel string, v any, code ...int) (err error)

type InboundConnection

type InboundConnection interface {
	Update(method, channel string, v any, code ...int) (err error)
}

type InboundPredicate

type InboundPredicate func(i *Inbound) (err error)

type Info

type Info struct {
	Name        string
	Description string
	UUID        string
}

func (*Info) GenerateUUID

func (x *Info) GenerateUUID()

type Options

type Options struct {
	Info
	Socket         string
	SocketFileMode os.FileMode
	// contains filtered or unexported fields
}

type Output

type Output interface {
	GetCode() int
	GetContent() any
}

type OutputData

type OutputData interface {
	GetCode() int
	Bind(v any) (err error)
}

type Request

type Request struct {
	ChannelData
	UUID    string `json:"uuid"`
	Content []byte `json:"content"`
}

func (Request) Bind

func (x Request) Bind(v any) (err error)

func (*Request) SetContent

func (x *Request) SetContent(v any) (err error)

type RequestHander

type RequestHander func(ctx *Context) Output

type RequestRouter

type RequestRouter interface {
	Set(method, channel string, handler RequestHander)
}

type RequestRouterCallback

type RequestRouterCallback func(router RequestRouter)

type Response

type Response struct {
	Data
	ChannelData
	UUID    string `json:"uuid"`
	Request Request
}

type Server

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

func (*Server) Auth

func (x *Server) Auth(callbacks ...AuthCallback)

func (*Server) Boot

func (x *Server) Boot(callbacks ...BootCallback)

func (*Server) Connect

func (x *Server) Connect(opts *Options) (errChan chan error)

func (*Server) Listen

func (x *Server) Listen(opts *Options) (err error)

func (*Server) OnClientInit

func (x *Server) OnClientInit(callbacks ...ClientInitCallback)

func (*Server) Routes

func (x *Server) Routes(callbacks ...RequestRouterCallback)

func (*Server) Run

func (x *Server) Run() (err error)

func (*Server) Stop

func (x *Server) Stop() (err error)

type ServerRequestRouter

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

func (*ServerRequestRouter) Delete

func (x *ServerRequestRouter) Delete(method, channel string)

func (*ServerRequestRouter) Get

func (x *ServerRequestRouter) Get(method, channel string) (handler RequestHander, ok bool)

func (*ServerRequestRouter) Set

func (x *ServerRequestRouter) Set(method, channel string, handler RequestHander)

type Update

type Update struct {
	ChannelData
	// UUID    string `json:"uuid"`
	Code    int    `json:"code"`
	Content []byte `json:"content"`
}

func (Update) Bind

func (x Update) Bind(v any) (err error)

func (Update) Data

func (x Update) Data() Data

func (*Update) SetContent

func (x *Update) SetContent(v any) (err error)

type UpdateHandler

type UpdateHandler func(data OutputData)

type UpdateRouter

type UpdateRouter interface {
	On(method, channel string, handler UpdateHandler)
}

type UpdateRouterCallback

type UpdateRouterCallback func(router UpdateRouter)

Jump to

Keyboard shortcuts

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