infra

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2024 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Error

func Error(r Ret) error

Error checks if the response is an error.

Types

type Crypto

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

Crypto is a struct for encrypting and decrypting data using AES CBC mode.

func NewCrypto

func NewCrypto(key, iv []byte) (*Crypto, error)

NewCrypto creates a new Crypto instance.

func (*Crypto) Decrypt

func (c *Crypto) Decrypt(data []byte) []byte

Decrypt decrypts the data.

func (*Crypto) Encrypt

func (c *Crypto) Encrypt(data []byte) []byte

Encrypt encrypts the data.

type Dispatcher

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

Dispatcher is to dispatch the response to the corresponding channel.

func NewDispatcher

func NewDispatcher() *Dispatcher

NewDispatcher creates a new dispatcher.

func (*Dispatcher) Close

func (d *Dispatcher) Close()

Close closes all channels.

func (*Dispatcher) Dispatch

func (d *Dispatcher) Dispatch(sn uint32, body []byte) error

Dispatch dispatches the response to the corresponding channel.

func (*Dispatcher) Register

func (d *Dispatcher) Register(sn uint32, ch *ProtobufChan)

Register registers a channel with a serial number.

type DispatcherHub

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

DispatcherHub is to store dispatchers for different proto id, key is proto id.

func NewDispatcherHub

func NewDispatcherHub() *DispatcherHub

NewDispatcherHub creates a new dispatcher hub.

func (*DispatcherHub) Close

func (h *DispatcherHub) Close()

Close closes all dispatchers.

func (*DispatcherHub) Dispatch

func (h *DispatcherHub) Dispatch(id uint32, sn uint32, body []byte) error

Dispatch dispatches the response to the corresponding channel.

func (*DispatcherHub) Register

func (h *DispatcherHub) Register(id uint32, sn uint32, ch *ProtobufChan)

Register registers a dispatcher with a proto id and serial number.

type ProtobufChan

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

ProtobufChan is a wrapper for chan *T, T is a struct and *T implements proto.Message.

func NewProtobufChan

func NewProtobufChan(i any) *ProtobufChan

NewProtobufChan creates a new ProtobufChan.

func (*ProtobufChan) Close

func (ch *ProtobufChan) Close()

Close closes the channel.

func (*ProtobufChan) Send

func (ch *ProtobufChan) Send(b []byte) error

Send unmarshals b into a proto message and send it to the channel.

type Ret

type Ret interface {
	GetRetType() int32
	GetRetMsg() string
}

Ret is the interface for response.

Jump to

Keyboard shortcuts

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