gonetwork

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2024 License: Apache-2.0 Imports: 15 Imported by: 2

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 Decode

func Decode(data []byte) (string, string, []byte)

func DecodeProto

func DecodeProto(data []byte, dataProto proto.Message) proto.Message

func Encode

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

func TLSCert

func TLSCert(domain string) (tls.Certificate, error)

Types

type CTcp

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

func TCPNewC

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

func (*CTcp) Close

func (c *CTcp) Close() error

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 WSNewC

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

func (*CWs) Close

func (c *CWs) Close() error

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 string, 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()
}

type ConnPool

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

func NewConnPool

func NewConnPool(maxConns int) *ConnPool

func (*ConnPool) CloseAll

func (p *ConnPool) CloseAll()

func (*ConnPool) Get

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

func (*ConnPool) Put

func (p *ConnPool) Put(conn net.Conn)

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 STcp

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

func TCPNewS

func TCPNewS(config ServerConfig) *STcp

func (*STcp) Broadcast

func (s *STcp) Broadcast(data []byte, except ...map[string]bool)

func (*STcp) GetConnection

func (s *STcp) GetConnection(connectionID string) net.Conn

func (*STcp) IsConnection

func (s *STcp) IsConnection(connectionID string) bool

func (*STcp) Listen

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

func (*STcp) Send

func (s *STcp) Send(connectionID string, data []byte)

func (*STcp) Shutdown

func (s *STcp) Shutdown()

type SWs

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

func WSNewS

func WSNewS(config ServerConfig) *SWs

func (*SWs) Broadcast

func (s *SWs) Broadcast(data []byte, except ...map[string]bool)

func (*SWs) GetConnection

func (s *SWs) GetConnection(connectionID string) *websocket.Conn

func (*SWs) IsConnection

func (s *SWs) IsConnection(connectionID string) bool

func (*SWs) Listen

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

func (*SWs) Send

func (s *SWs) Send(connectionID string, data []byte)

func (*SWs) Shutdown

func (s *SWs) Shutdown()

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, except ...map[string]bool)

func (*Server) GetConnection

func (s *Server) GetConnection(connectionID string) interface{}

func (*Server) Listen

func (s *Server) Listen()

func (*Server) Send

func (s *Server) Send(connectionID string, 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)
}

type TCPConnectionEntry

type TCPConnectionEntry struct {
	Conn net.Conn
}

type WSConnectionEntry

type WSConnectionEntry struct {
	Conn *websocket.Conn
}

Jump to

Keyboard shortcuts

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