server

package
v0.0.0-...-4e26a97 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2022 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const ReqHeaderLen = 8
View Source
const RespHeaderLen = 8

Variables

View Source
var (
	ErrServerClosed = errors.New("server: Server closed")
)

Functions

This section is empty.

Types

type Cmd

type Cmd uint32
const (
	CmdCreateMessageId Cmd = iota + 1
	CmdSendMessage
)

type Config

type Config struct {
	Addr               string `yaml:"addr"`
	ReadTimeoutMillis  int    `yaml:"read_timeout_millis"`
	WriteTimeoutMillis int    `yaml:"write_timeout_millis"`
}

type Handler

type Handler func(req *Request) (status Status, payload []byte)

type Request

type Request struct {
	Cmd    Cmd
	Length uint32
	Body   []byte
}

type Server

type Server struct {
	Addr         string
	ReadTimeout  time.Duration
	WriteTimeout time.Duration
	IdleTimeout  time.Duration
	// contains filtered or unexported fields
}

func NewServer

func NewServer(config *Config) *Server

func (*Server) Handle

func (srv *Server) Handle(cmd Cmd, handler Handler)

func (*Server) ListenAndServe

func (srv *Server) ListenAndServe() (err error)

func (*Server) Shutdown

func (srv *Server) Shutdown(ctx context.Context) error

type Status

type Status uint32
const (
	StatusOk Status = iota
	StatusMsgReadHeaderErr
	StatusMsgReadMessageErr
	StatusNotFoundCmd
	StatusBadDomain
)

Jump to

Keyboard shortcuts

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