model

package module
v0.0.0-...-0833198 Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2022 License: Unlicense Imports: 11 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

View Source
var MAX_CONNECTION_RETRIES = 5
View Source
var MSG_DELIM = "\n"
View Source
var RETRY_TIMEOUT = 5 * time.Second

Functions

func IsActionType

func IsActionType(action *Action, typ string) bool

Types

type Action

type Action struct {
	Type      string      `json:"type"`
	Payload   interface{} `json:"payload"`
	Timestamp int64       `json:"timestamp"`
	Source    string      `json:"source"`
	SessionId string      `json:"sessionId"`
}

func CreateAction

func CreateAction(typ string, payload interface{}, sessionId string) Action

func CreateActionWithSource

func CreateActionWithSource(typ string, payload interface{}, sessionId string, source string) Action

func (*Action) GetType

func (a *Action) GetType() string

func (*Action) HasPayload

func (a *Action) HasPayload() bool

func (*Action) IsGroup

func (a *Action) IsGroup(group string) bool

func (*Action) IsType

func (a *Action) IsType(typ string) bool

func (*Action) ReqType

func (a *Action) ReqType() string

func (*Action) ResType

func (a *Action) ResType() string

type Handler

type Handler[T any] struct {
	Id       string
	Trigger  func(action Action) bool
	Request  func(action Action) (T, bool)
	Response func(res T) []Action
	Produces string
}

func CreateHandler

func CreateHandler[T any](
	id string,
	trigger func(action Action) bool,
	request func(action Action) (T, bool),
	response func(res T) []Action,
	produces string,
) Handler[T]

type IdExchange

type IdExchange struct {
	ConnectionId string `json:"connectionId"`
}

type SockClient

type SockClient[T any] struct {
	Config  SockClientConfig `validate:"required"`
	Handler Handler[T]

	SendFn func(action Action)
	// contains filtered or unexported fields
}

func (*SockClient[T]) Connect

func (sc *SockClient[T]) Connect()

func (*SockClient[T]) ReadAction

func (sc *SockClient[T]) ReadAction() Action

func (*SockClient[T]) Send

func (sc *SockClient[T]) Send(action Action)

type SockClientConfig

type SockClientConfig struct {
	Prot string
	Host string
	Port string
}

func (*SockClientConfig) ConnSrv

func (scc *SockClientConfig) ConnSrv() string

func (*SockClientConfig) ConnUrl

func (scc *SockClientConfig) ConnUrl() string

type SockServer

type SockServer struct {
	Config      SockClientConfig
	Connections []net.Conn
}

func (*SockServer) Listen

func (sc *SockServer) Listen()

type WebSocketServer

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

func NewWebSocketServer

func NewWebSocketServer(config SockClientConfig) WebSocketServer

func (*WebSocketServer) Run

func (wss *WebSocketServer) Run()

Jump to

Keyboard shortcuts

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