gonetwork

package module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2024 License: Apache-2.0 Imports: 16 Imported by: 0

README

gonetwork

KISS (Keep It Simple, Stupid) networking written in Go.

Current protocols

  • TCP: TCP server and client unsecure/secure with TLS encryption.
  • WebSoket: WebSocket server and client unsecure/secure with TLS encryption.

Documentation

Index

Constants

This section is empty.

Variables

Functions

func EncodeMessage added in v1.1.0

func EncodeMessage(dataHandler, dataType string, dataProto proto.Message) ([]byte, error)

func TLSCert

func TLSCert(certFile, keyFile string) (tls.Certificate, error)

Types

type CTcp

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

func CTCPNew added in v1.1.0

func CTCPNew(config ClientConfig, ctx context.Context, cancel context.CancelFunc) *CTcp

func (*CTcp) Connect

func (c *CTcp) Connect() error

func (*CTcp) Disconnect

func (c *CTcp) Disconnect()

func (*CTcp) Send

func (c *CTcp) Send(data []byte) error

type CWs

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

func CWSNew added in v1.1.0

func CWSNew(config ClientConfig, ctx context.Context, cancel context.CancelFunc) *CWs

func (*CWs) Connect

func (c *CWs) Connect() error

func (*CWs) Disconnect

func (c *CWs) Disconnect()

func (*CWs) Send

func (c *CWs) Send(data []byte) error

type Client

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

func NewClient

func NewClient(config ClientConfig) *Client

func (*Client) Connect

func (c *Client) Connect() error

func (*Client) Disconnect

func (c *Client) Disconnect()

func (*Client) Send

func (c *Client) Send(dataHandler, dataType string, dataProto proto.Message) error

type ClientConfig

type ClientConfig struct {
	Address        string
	Port           string
	Secure         bool
	Type           string
	OnConnected    func()
	OnData         func(data []byte)
	OnDisconnected func()
	CertFile       string
}

type ClientConnection added in v1.1.0

type ClientConnection interface {
	Connect() error
	Send(data []byte) error
	Disconnect()
}

type ConnPool

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

func NewConnPool

func NewConnPool(maxConns int, timeout time.Duration) *ConnPool

func (*ConnPool) Get

func (p *ConnPool) Get() (net.Conn, error)

type SMessage

type SMessage struct {
	Handler string `protobuf:"bytes,1,opt,name=handler,proto3" json:"handler,omitempty"`
	Type    string `protobuf:"bytes,2,opt,name=type,proto3" json:"type,omitempty"`
	Proto   []byte `protobuf:"bytes,3,opt,name=proto,proto3" json:"proto,omitempty"`
	// contains filtered or unexported fields
}

func (*SMessage) Descriptor deprecated

func (*SMessage) Descriptor() ([]byte, []int)

Deprecated: Use SMessage.ProtoReflect.Descriptor instead.

func (*SMessage) GetHandler

func (x *SMessage) GetHandler() string

func (*SMessage) GetProto

func (x *SMessage) GetProto() []byte

func (*SMessage) GetType

func (x *SMessage) GetType() string

func (*SMessage) ProtoMessage

func (*SMessage) ProtoMessage()

func (*SMessage) ProtoReflect

func (x *SMessage) ProtoReflect() protoreflect.Message

func (*SMessage) Reset

func (x *SMessage) Reset()

func (*SMessage) String

func (x *SMessage) String() string

type Server

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

func NewServer

func NewServer(config ServerConfig) *Server

func (*Server) Broadcast

func (s *Server) Broadcast(dataHandler, dataType string, data proto.Message)

func (*Server) Disconnect added in v1.1.0

func (s *Server) Disconnect(connectionID string)

func (*Server) Listen

func (s *Server) Listen()

func (*Server) Send

func (s *Server) Send(connectionID, dataHandler, dataType string, data proto.Message)

func (*Server) Shutdown

func (s *Server) Shutdown()

type ServerConfig

type ServerConfig struct {
	Address        string
	Port           string
	Domain         string
	TCPPort        string
	WSPort         string
	Secure         bool
	MaxWorkers     int
	OnConnected    func(connectionID string)
	OnData         func(connectionID string, data []byte)
	OnDisconnected func(connectionID string)
	CertFile       string
	KeyFile        string
	AllowedOrigins []string
}

type ServerConnection added in v1.1.0

type ServerConnection interface {
	Listen(ctx context.Context) error
	Broadcast(dataHandler, dataType string, data proto.Message)
	Send(connectionID string, dataHandler, dataType string, data proto.Message) error
	Disconnect(connectionID string)
	Shutdown()
}

type TCPServer added in v1.1.0

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

func STCPNew added in v1.1.0

func STCPNew(config ServerConfig) *TCPServer

func (*TCPServer) Broadcast added in v1.1.0

func (s *TCPServer) Broadcast(dataHandler, dataType string, data proto.Message)

func (*TCPServer) Disconnect added in v1.1.0

func (s *TCPServer) Disconnect(connectionID string)

func (*TCPServer) Listen added in v1.1.0

func (s *TCPServer) Listen(ctx context.Context) error

func (*TCPServer) Send added in v1.1.0

func (s *TCPServer) Send(connectionID, dataHandler, dataType string, data proto.Message) error

func (*TCPServer) Shutdown added in v1.1.0

func (s *TCPServer) Shutdown()

type WebSocketServer added in v1.1.0

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

func SWSNew added in v1.1.0

func SWSNew(config ServerConfig) *WebSocketServer

func (*WebSocketServer) Broadcast added in v1.1.0

func (s *WebSocketServer) Broadcast(dataHandler, dataType string, data proto.Message)

func (*WebSocketServer) Disconnect added in v1.1.0

func (s *WebSocketServer) Disconnect(connectionID string)

func (*WebSocketServer) Listen added in v1.1.0

func (s *WebSocketServer) Listen(ctx context.Context) error

func (*WebSocketServer) Send added in v1.1.0

func (s *WebSocketServer) Send(connectionID, dataHandler, dataType string, data proto.Message) error

func (*WebSocketServer) Shutdown added in v1.1.0

func (s *WebSocketServer) Shutdown()

Jump to

Keyboard shortcuts

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