server

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2023 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Conn

type Conn interface {
	Name() string
	SetName(name string)
	FD() int64
	SetFD(int64)
	Host() string
	ClientIP() string
	Ping() error
	Pong() error
	Write(messageType int, msg []byte) (int, error)
	Close() error
	SetLastPing(time.Time)
	LastPing() time.Time
	Conn() *websocket.Conn
	Response() http.ResponseWriter
	Request() *http.Request
	SubProtocols() []string
	SetDeadline(t time.Time) error
	socket.Packer
}

type Middle

type Middle router.Middle[*socket.Stream[Conn]]

type Server

type Server[T any] struct {
	Name string
	// Host 服务Host
	Addr string
	// TLS FILE
	CertFile string
	// TLS KEY
	KeyFile string
	// TLS
	TLSConfig *tls.Config
	// Path
	Path string

	OnOpen      func(conn Conn)
	OnMessage   func(conn Conn, msg []byte)
	OnClose     func(conn Conn)
	OnError     func(stream *socket.Stream[Conn], err error)
	OnException func(err error)
	OnSuccess   func()
	OnRaw       func(w http.ResponseWriter, r *http.Request)
	OnUnknown   func(conn Conn, message []byte, next Middle)

	HeartBeatTimeout  time.Duration
	HeartBeatInterval time.Duration
	HandshakeTimeout  time.Duration
	DailTimeout       time.Duration

	ReadBufferSize  int
	WriteBufferSize int

	SubProtocols []string
	CheckOrigin  func(r *http.Request) bool
	PingHandler  func(conn Conn) func(data string) error
	PongHandler  func(conn Conn) func(data string) error

	ReadTimeout       time.Duration
	WriteTimeout      time.Duration
	IdleTimeout       time.Duration
	ReadHeaderTimeout time.Duration
	MaxHeaderBytes    int
	// contains filtered or unexported fields
}

func (*Server[T]) Conn

func (s *Server[T]) Conn(fd int64) (Conn, error)

func (*Server[T]) ConnLen

func (s *Server[T]) ConnLen() int

func (*Server[T]) GetDailTimeout

func (s *Server[T]) GetDailTimeout() time.Duration

func (*Server[T]) GetRouter

func (s *Server[T]) GetRouter() *router.Router[*socket.Stream[Conn], T]

func (*Server[T]) LocalAddr

func (s *Server[T]) LocalAddr() net.Addr

func (*Server[T]) Range

func (s *Server[T]) Range(fn func(conn Conn))

func (*Server[T]) Ready

func (s *Server[T]) Ready()

func (*Server[T]) Sender

func (s *Server[T]) Sender(fd int64) (socket.Emitter[Conn], error)

func (*Server[T]) ServeHTTP

func (s *Server[T]) ServeHTTP(w http.ResponseWriter, r *http.Request)

func (*Server[T]) SetRouter

func (s *Server[T]) SetRouter(router *router.Router[*socket.Stream[Conn], T]) *Server[T]

func (*Server[T]) Shutdown

func (s *Server[T]) Shutdown() error

func (*Server[T]) Start

func (s *Server[T]) Start()

func (*Server[T]) Use

func (s *Server[T]) Use(middle ...func(next Middle) Middle)

Jump to

Keyboard shortcuts

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