network

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2025 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidKeyLength = fmt.Errorf("invalid key length")
)

Functions

func GenerateKey

func GenerateKey() ([]byte, error)

func IsClosedError

func IsClosedError(err error) bool

func SerializeMessage

func SerializeMessage(m *Message) ([]byte, error)

Types

type AdvancedConn

type AdvancedConn interface {
	Conn() BasicConn
	Read() (*Message, error)
	Write(m *Message) error
	Close() error
}

type BasicConn

type BasicConn interface {
	Read(b []byte) (int, error)
	Write(b []byte) (int, error)
	Close() error
}

type BasicListener

type BasicListener interface {
	Accept() (BasicConn, error)
	Close() error
}

type Conn

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

func NewConn

func NewConn(conn BasicConn) *Conn

func (*Conn) Close

func (c *Conn) Close() error

func (*Conn) Conn

func (c *Conn) Conn() BasicConn

func (*Conn) Read

func (c *Conn) Read() (*Message, error)

func (*Conn) Write

func (c *Conn) Write(m *Message) error

func (*Conn) WriteFrame

func (c *Conn) WriteFrame(frame []byte) error

type Encryption

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

func NewEncryption

func NewEncryption(encryptionKey, decryptionKey []byte) (*Encryption, error)

func (*Encryption) Decrypt

func (e *Encryption) Decrypt(encryptedData []byte) ([]byte, error)

func (*Encryption) Encrypt

func (e *Encryption) Encrypt(data []byte) ([]byte, error)

type Listener

type Listener struct {
	Listener BasicListener
}

func NewListener

func NewListener(listener BasicListener) *Listener

func (*Listener) Accept

func (l *Listener) Accept() (*Conn, error)

func (*Listener) Close

func (l *Listener) Close() error

type Message

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

func DeserializeMessage

func DeserializeMessage(data []byte) (*Message, error)

func NewMessage

func NewMessage(headers map[string]string, body []byte) *Message

func (*Message) Body

func (m *Message) Body() []byte

func (*Message) BodyTo

func (m *Message) BodyTo(v any) error

func (*Message) DeleteHeader

func (m *Message) DeleteHeader(key string)

func (*Message) GetHeader

func (m *Message) GetHeader(key string) (string, bool)

func (*Message) Headers

func (m *Message) Headers() map[string]string

func (*Message) SetHeader

func (m *Message) SetHeader(key, value string)

type MockAdvancedConn

type MockAdvancedConn struct {
	mock.Mock
}

MockAdvancedConn is an autogenerated mock type for the AdvancedConn type

func NewMockAdvancedConn

func NewMockAdvancedConn(t interface {
	mock.TestingT
	Cleanup(func())
}) *MockAdvancedConn

NewMockAdvancedConn creates a new instance of MockAdvancedConn. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. The first argument is typically a *testing.T value.

func (*MockAdvancedConn) Close

func (_mock *MockAdvancedConn) Close() error

Close provides a mock function for the type MockAdvancedConn

func (*MockAdvancedConn) Conn

func (_mock *MockAdvancedConn) Conn() BasicConn

Conn provides a mock function for the type MockAdvancedConn

func (*MockAdvancedConn) EXPECT

func (*MockAdvancedConn) Read

func (_mock *MockAdvancedConn) Read() (*Message, error)

Read provides a mock function for the type MockAdvancedConn

func (*MockAdvancedConn) Write

func (_mock *MockAdvancedConn) Write(m *Message) error

Write provides a mock function for the type MockAdvancedConn

type MockAdvancedConn_Close_Call

type MockAdvancedConn_Close_Call struct {
	*mock.Call
}

MockAdvancedConn_Close_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Close'

func (*MockAdvancedConn_Close_Call) Return

func (*MockAdvancedConn_Close_Call) Run

func (*MockAdvancedConn_Close_Call) RunAndReturn

func (_c *MockAdvancedConn_Close_Call) RunAndReturn(run func() error) *MockAdvancedConn_Close_Call

type MockAdvancedConn_Conn_Call

type MockAdvancedConn_Conn_Call struct {
	*mock.Call
}

MockAdvancedConn_Conn_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Conn'

func (*MockAdvancedConn_Conn_Call) Return

func (*MockAdvancedConn_Conn_Call) Run

func (*MockAdvancedConn_Conn_Call) RunAndReturn

func (_c *MockAdvancedConn_Conn_Call) RunAndReturn(run func() BasicConn) *MockAdvancedConn_Conn_Call

type MockAdvancedConn_Expecter

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

func (*MockAdvancedConn_Expecter) Close

Close is a helper method to define mock.On call

func (*MockAdvancedConn_Expecter) Conn

Conn is a helper method to define mock.On call

func (*MockAdvancedConn_Expecter) Read

Read is a helper method to define mock.On call

func (*MockAdvancedConn_Expecter) Write

func (_e *MockAdvancedConn_Expecter) Write(m interface{}) *MockAdvancedConn_Write_Call

Write is a helper method to define mock.On call

  • m *Message

type MockAdvancedConn_Read_Call

type MockAdvancedConn_Read_Call struct {
	*mock.Call
}

MockAdvancedConn_Read_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Read'

func (*MockAdvancedConn_Read_Call) Return

func (*MockAdvancedConn_Read_Call) Run

func (*MockAdvancedConn_Read_Call) RunAndReturn

func (_c *MockAdvancedConn_Read_Call) RunAndReturn(run func() (*Message, error)) *MockAdvancedConn_Read_Call

type MockAdvancedConn_Write_Call

type MockAdvancedConn_Write_Call struct {
	*mock.Call
}

MockAdvancedConn_Write_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Write'

func (*MockAdvancedConn_Write_Call) Return

func (*MockAdvancedConn_Write_Call) Run

func (*MockAdvancedConn_Write_Call) RunAndReturn

func (_c *MockAdvancedConn_Write_Call) RunAndReturn(run func(m *Message) error) *MockAdvancedConn_Write_Call

type MockBasicConn

type MockBasicConn struct {
	mock.Mock
}

MockBasicConn is an autogenerated mock type for the BasicConn type

func NewMockBasicConn

func NewMockBasicConn(t interface {
	mock.TestingT
	Cleanup(func())
}) *MockBasicConn

NewMockBasicConn creates a new instance of MockBasicConn. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. The first argument is typically a *testing.T value.

func (*MockBasicConn) Close

func (_mock *MockBasicConn) Close() error

Close provides a mock function for the type MockBasicConn

func (*MockBasicConn) EXPECT

func (_m *MockBasicConn) EXPECT() *MockBasicConn_Expecter

func (*MockBasicConn) Read

func (_mock *MockBasicConn) Read(b []byte) (int, error)

Read provides a mock function for the type MockBasicConn

func (*MockBasicConn) Write

func (_mock *MockBasicConn) Write(b []byte) (int, error)

Write provides a mock function for the type MockBasicConn

type MockBasicConn_Close_Call

type MockBasicConn_Close_Call struct {
	*mock.Call
}

MockBasicConn_Close_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Close'

func (*MockBasicConn_Close_Call) Return

func (*MockBasicConn_Close_Call) Run

func (*MockBasicConn_Close_Call) RunAndReturn

func (_c *MockBasicConn_Close_Call) RunAndReturn(run func() error) *MockBasicConn_Close_Call

type MockBasicConn_Expecter

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

func (*MockBasicConn_Expecter) Close

Close is a helper method to define mock.On call

func (*MockBasicConn_Expecter) Read

func (_e *MockBasicConn_Expecter) Read(b interface{}) *MockBasicConn_Read_Call

Read is a helper method to define mock.On call

  • b []byte

func (*MockBasicConn_Expecter) Write

func (_e *MockBasicConn_Expecter) Write(b interface{}) *MockBasicConn_Write_Call

Write is a helper method to define mock.On call

  • b []byte

type MockBasicConn_Read_Call

type MockBasicConn_Read_Call struct {
	*mock.Call
}

MockBasicConn_Read_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Read'

func (*MockBasicConn_Read_Call) Return

func (*MockBasicConn_Read_Call) Run

func (_c *MockBasicConn_Read_Call) Run(run func(b []byte)) *MockBasicConn_Read_Call

func (*MockBasicConn_Read_Call) RunAndReturn

func (_c *MockBasicConn_Read_Call) RunAndReturn(run func(b []byte) (int, error)) *MockBasicConn_Read_Call

type MockBasicConn_Write_Call

type MockBasicConn_Write_Call struct {
	*mock.Call
}

MockBasicConn_Write_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Write'

func (*MockBasicConn_Write_Call) Return

func (*MockBasicConn_Write_Call) Run

func (_c *MockBasicConn_Write_Call) Run(run func(b []byte)) *MockBasicConn_Write_Call

func (*MockBasicConn_Write_Call) RunAndReturn

func (_c *MockBasicConn_Write_Call) RunAndReturn(run func(b []byte) (int, error)) *MockBasicConn_Write_Call

type MockBasicListener

type MockBasicListener struct {
	mock.Mock
}

MockBasicListener is an autogenerated mock type for the BasicListener type

func NewMockBasicListener

func NewMockBasicListener(t interface {
	mock.TestingT
	Cleanup(func())
}) *MockBasicListener

NewMockBasicListener creates a new instance of MockBasicListener. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. The first argument is typically a *testing.T value.

func (*MockBasicListener) Accept

func (_mock *MockBasicListener) Accept() (BasicConn, error)

Accept provides a mock function for the type MockBasicListener

func (*MockBasicListener) Close

func (_mock *MockBasicListener) Close() error

Close provides a mock function for the type MockBasicListener

func (*MockBasicListener) EXPECT

type MockBasicListener_Accept_Call

type MockBasicListener_Accept_Call struct {
	*mock.Call
}

MockBasicListener_Accept_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Accept'

func (*MockBasicListener_Accept_Call) Return

func (*MockBasicListener_Accept_Call) Run

func (*MockBasicListener_Accept_Call) RunAndReturn

type MockBasicListener_Close_Call

type MockBasicListener_Close_Call struct {
	*mock.Call
}

MockBasicListener_Close_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Close'

func (*MockBasicListener_Close_Call) Return

func (*MockBasicListener_Close_Call) Run

func (*MockBasicListener_Close_Call) RunAndReturn

func (_c *MockBasicListener_Close_Call) RunAndReturn(run func() error) *MockBasicListener_Close_Call

type MockBasicListener_Expecter

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

func (*MockBasicListener_Expecter) Accept

Accept is a helper method to define mock.On call

func (*MockBasicListener_Expecter) Close

Close is a helper method to define mock.On call

type MockSecureComponent

type MockSecureComponent struct {
	mock.Mock
}

MockSecureComponent is an autogenerated mock type for the SecureComponent type

func NewMockSecureComponent

func NewMockSecureComponent(t interface {
	mock.TestingT
	Cleanup(func())
}) *MockSecureComponent

NewMockSecureComponent creates a new instance of MockSecureComponent. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. The first argument is typically a *testing.T value.

func (*MockSecureComponent) Decrypt

func (_mock *MockSecureComponent) Decrypt(data []byte) ([]byte, error)

Decrypt provides a mock function for the type MockSecureComponent

func (*MockSecureComponent) EXPECT

func (*MockSecureComponent) Encrypt

func (_mock *MockSecureComponent) Encrypt(data []byte) ([]byte, error)

Encrypt provides a mock function for the type MockSecureComponent

type MockSecureComponent_Decrypt_Call

type MockSecureComponent_Decrypt_Call struct {
	*mock.Call
}

MockSecureComponent_Decrypt_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Decrypt'

func (*MockSecureComponent_Decrypt_Call) Return

func (*MockSecureComponent_Decrypt_Call) Run

func (*MockSecureComponent_Decrypt_Call) RunAndReturn

func (_c *MockSecureComponent_Decrypt_Call) RunAndReturn(run func(data []byte) ([]byte, error)) *MockSecureComponent_Decrypt_Call

type MockSecureComponent_Encrypt_Call

type MockSecureComponent_Encrypt_Call struct {
	*mock.Call
}

MockSecureComponent_Encrypt_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Encrypt'

func (*MockSecureComponent_Encrypt_Call) Return

func (*MockSecureComponent_Encrypt_Call) Run

func (*MockSecureComponent_Encrypt_Call) RunAndReturn

func (_c *MockSecureComponent_Encrypt_Call) RunAndReturn(run func(data []byte) ([]byte, error)) *MockSecureComponent_Encrypt_Call

type MockSecureComponent_Expecter

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

func (*MockSecureComponent_Expecter) Decrypt

func (_e *MockSecureComponent_Expecter) Decrypt(data interface{}) *MockSecureComponent_Decrypt_Call

Decrypt is a helper method to define mock.On call

  • data []byte

func (*MockSecureComponent_Expecter) Encrypt

func (_e *MockSecureComponent_Expecter) Encrypt(data interface{}) *MockSecureComponent_Encrypt_Call

Encrypt is a helper method to define mock.On call

  • data []byte

type MockTransport

type MockTransport struct {
	mock.Mock
}

MockTransport is an autogenerated mock type for the Transport type

func NewMockTransport

func NewMockTransport(t interface {
	mock.TestingT
	Cleanup(func())
}) *MockTransport

NewMockTransport creates a new instance of MockTransport. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. The first argument is typically a *testing.T value.

func (*MockTransport) Connect

func (_mock *MockTransport) Connect(address string) (*Conn, error)

Connect provides a mock function for the type MockTransport

func (*MockTransport) EXPECT

func (_m *MockTransport) EXPECT() *MockTransport_Expecter

func (*MockTransport) Listen

func (_mock *MockTransport) Listen(address string) (*Listener, error)

Listen provides a mock function for the type MockTransport

type MockTransport_Connect_Call

type MockTransport_Connect_Call struct {
	*mock.Call
}

MockTransport_Connect_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Connect'

func (*MockTransport_Connect_Call) Return

func (*MockTransport_Connect_Call) Run

func (_c *MockTransport_Connect_Call) Run(run func(address string)) *MockTransport_Connect_Call

func (*MockTransport_Connect_Call) RunAndReturn

func (_c *MockTransport_Connect_Call) RunAndReturn(run func(address string) (*Conn, error)) *MockTransport_Connect_Call

type MockTransport_Expecter

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

func (*MockTransport_Expecter) Connect

func (_e *MockTransport_Expecter) Connect(address interface{}) *MockTransport_Connect_Call

Connect is a helper method to define mock.On call

  • address string

func (*MockTransport_Expecter) Listen

func (_e *MockTransport_Expecter) Listen(address interface{}) *MockTransport_Listen_Call

Listen is a helper method to define mock.On call

  • address string

type MockTransport_Listen_Call

type MockTransport_Listen_Call struct {
	*mock.Call
}

MockTransport_Listen_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Listen'

func (*MockTransport_Listen_Call) Return

func (*MockTransport_Listen_Call) Run

func (_c *MockTransport_Listen_Call) Run(run func(address string)) *MockTransport_Listen_Call

func (*MockTransport_Listen_Call) RunAndReturn

func (_c *MockTransport_Listen_Call) RunAndReturn(run func(address string) (*Listener, error)) *MockTransport_Listen_Call

type SecureComponent

type SecureComponent interface {
	Encrypt(data []byte) ([]byte, error)
	Decrypt(data []byte) ([]byte, error)
}

type SecureConn

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

func NewSecureConn

func NewSecureConn(conn Conn, sc SecureComponent) *SecureConn

func (*SecureConn) Close

func (c *SecureConn) Close() error

func (*SecureConn) Conn

func (c *SecureConn) Conn() BasicConn

func (*SecureConn) Read

func (c *SecureConn) Read() (*Message, error)

func (*SecureConn) Write

func (c *SecureConn) Write(m *Message) error

type Transport

type Transport interface {
	Connect(address string) (*Conn, error)
	Listen(address string) (*Listener, error)
}

func NewTcpTransport

func NewTcpTransport() Transport

Jump to

Keyboard shortcuts

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