com

package
v3.0.5 Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2023 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultCallTimeout = 7 * time.Second

Variables

View Source
var NilUid = Uid{xid.NilID()}

Functions

This section is empty.

Types

type Client

type Client struct {
	websocket.Client
}

func (*Client) Connect added in v3.0.5

func (c *Client) Connect(addr url.URL) (*Connection, error)

type Connection added in v3.0.5

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

func (Connection) IsServer added in v3.0.5

func (c Connection) IsServer() bool

type HasCallId added in v3.0.5

type HasCallId interface {
	SetGetId(fmt.Stringer)
}

type Map added in v3.0.5

type Map[K comparable, V any] struct {
	// contains filtered or unexported fields
}

Map defines a concurrent-safe map structure. Keep in mind that the underlying map structure will grow indefinitely.

func (*Map[K, V]) Find added in v3.0.5

func (m *Map[K, V]) Find(key K) (v V, ok bool)

Find returns the first value found and a boolean flag if its found or not.

func (*Map[K, V]) FindBy added in v3.0.5

func (m *Map[K, V]) FindBy(fn func(v V) bool) (v V, ok bool)

FindBy searches the first key-value with the provided predicate function.

func (*Map[K, V]) ForEach added in v3.0.5

func (m *Map[K, V]) ForEach(fn func(v V))

ForEach processes every element with the provided callback function.

func (*Map[K, _]) Has added in v3.0.5

func (m *Map[K, _]) Has(key K) bool

func (*Map[_, _]) Len added in v3.0.5

func (m *Map[_, _]) Len() int

func (*Map[K, V]) Pop added in v3.0.5

func (m *Map[K, V]) Pop(key K) V

func (*Map[K, V]) Put added in v3.0.5

func (m *Map[K, V]) Put(key K, v V)

func (*Map[K, _]) Remove added in v3.0.5

func (m *Map[K, _]) Remove(key K)

type NetClient

type NetClient interface {
	Disconnect()
	Id() Uid
}

type NetMap

type NetMap[T NetClient] struct{ Map[Uid, T] }

func NewNetMap

func NewNetMap[T NetClient]() NetMap[T]

func (*NetMap[T]) Add

func (m *NetMap[T]) Add(client T)

func (*NetMap[T]) Remove

func (m *NetMap[T]) Remove(client T)

func (*NetMap[T]) RemoveDisconnect added in v3.0.5

func (m *NetMap[T]) RemoveDisconnect(client T)

type Packet added in v3.0.5

type Packet[T ~uint8] interface {
	GetId() Uid
	GetType() T
	GetPayload() []byte
}

type Packet2 added in v3.0.5

type Packet2[T any] interface {
	SetId(string)
	SetType(uint8)
	SetPayload(any)
	SetGetId(fmt.Stringer)
	GetPayload() any
	*T // non-interface type constraint element
}

type RPC added in v3.0.5

type RPC[T ~uint8, P Packet[T]] struct {
	CallTimeout time.Duration
	Handler     func(P)
	Transport   Transport
	// contains filtered or unexported fields
}

func NewRPC added in v3.0.5

func NewRPC[T ~uint8, P Packet[T]]() *RPC[T, P]

func (*RPC[_, _]) Call added in v3.0.5

func (t *RPC[_, _]) Call(w Writer, rq HasCallId) ([]byte, error)

func (*RPC[_, _]) Cleanup added in v3.0.5

func (t *RPC[_, _]) Cleanup()

func (*RPC[_, _]) Send added in v3.0.5

func (t *RPC[_, _]) Send(w Writer, packet any) error

type Server added in v3.0.5

type Server struct {
	websocket.Server
}

func (*Server) Connect added in v3.0.5

func (s *Server) Connect(w http.ResponseWriter, r *http.Request) (*Connection, error)

func (*Server) Origin added in v3.0.5

func (s *Server) Origin(host string)

type SocketClient

type SocketClient[T ~uint8, P Packet[T], X any, P2 Packet2[X]] struct {
	// contains filtered or unexported fields
}

func NewConnection added in v3.0.5

func NewConnection[T ~uint8, P Packet[T], X any, P2 Packet2[X]](conn *Connection, id Uid, log *logger.Logger) *SocketClient[T, P, X, P2]

func (*SocketClient[_, _, _, _]) Disconnect added in v3.0.5

func (c *SocketClient[_, _, _, _]) Disconnect()

func (*SocketClient[_, _, _, _]) Id

func (c *SocketClient[_, _, _, _]) Id() Uid

func (*SocketClient[T, P, X, P2]) Notify

func (c *SocketClient[T, P, X, P2]) Notify(t T, data any)

Notify just sends a message and goes further.

func (*SocketClient[T, P, _, _]) ProcessPackets added in v3.0.5

func (c *SocketClient[T, P, _, _]) ProcessPackets(fn func(in P) error) chan struct{}

func (*SocketClient[_, P, X, P2]) Route

func (c *SocketClient[_, P, X, P2]) Route(in P, out P2)

func (*SocketClient[T, P, X, P2]) Send

func (c *SocketClient[T, P, X, P2]) Send(t T, data any) ([]byte, error)

Send makes a blocking call.

func (*SocketClient[_, _, _, _]) String

func (c *SocketClient[_, _, _, _]) String() string

type Transport added in v3.0.5

type Transport interface {
	SetMessageHandler(func([]byte, error))
}

type Uid added in v3.0.5

type Uid struct {
	xid.ID
}

func NewUid added in v3.0.5

func NewUid() Uid

func UidFromString added in v3.0.5

func UidFromString(id string) (Uid, error)

func (Uid) Short added in v3.0.5

func (u Uid) Short() string

type Writer added in v3.0.5

type Writer interface {
	Write([]byte)
}

Jump to

Keyboard shortcuts

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