Documentation
¶
Index ¶
- Constants
- func AddressToClientId(connection IConnection) string
- func CloseClient(request IRequest, clientId string, data []byte) error
- func GbToUtf8(s []byte) ([]byte, error)
- func IsOnLine(request IRequest, clientId string) bool
- func SendToClient(request IRequest, clientId string, data []byte) error
- func Utf8ToGb(s []byte) ([]byte, error)
- type Connection
- func (c *Connection) DelProperty(key string)
- func (c *Connection) GetConn() *net.TCPConn
- func (c *Connection) GetID() uint32
- func (c *Connection) GetProperty(key string) (interface{}, error)
- func (c *Connection) GetServer() IServer
- func (c *Connection) RemoteAddr() net.Addr
- func (c *Connection) Send(data []byte) error
- func (c *Connection) SetPackProto(proto IPack)
- func (c *Connection) SetProperty(key string, val interface{})
- func (c *Connection) SetProtoPack(proto IPack)
- func (c *Connection) Start()
- func (c *Connection) StartReader()
- func (c *Connection) StartWriter()
- func (c *Connection) Stop()
- type HLog
- type HandleFunc
- type Handler
- func (h *Handler) Abort()
- func (h *Handler) After(rf HandlerFunc)
- func (h *Handler) Before(rf HandlerFunc)
- func (h *Handler) RunHandler(request IRequest)
- func (h *Handler) RunWorkPool()
- func (h *Handler) SendToTasks(rq IRequest)
- func (h *Handler) SetEventHandle(event IEvent)
- func (h *Handler) SetWorkPoolSize(size uint32)
- func (h *Handler) Use(rf HandlerFunc)
- type HandlerFunc
- type IConnection
- type IEvent
- type IHandler
- type IManager
- type IMessage
- type IPack
- type IRequest
- type IServer
- type Listener
- type Manager
- type Message
- type Options
- type Request
- type Server
- func (s *Server) Abort()
- func (s *Server) After(rf HandlerFunc)
- func (s *Server) Before(rf HandlerFunc)
- func (s Server) GetConfig() *viper.Viper
- func (s *Server) GetManager() IManager
- func (s *Server) GetRid() *uint32
- func (s *Server) OnStart(hook hookHandler)
- func (s *Server) OnStop(c hookHandler)
- func (s *Server) OverLoad(o overloadHandler)
- func (s *Server) Run()
- func (s *Server) SetConfig(conf *viper.Viper)
- func (s *Server) SetEventHandle(event IEvent)
- func (s *Server) SetMaxCon(size uint32)
- func (s *Server) SetProtoPack(proto IPack)
- func (s *Server) SetWorkPoolSize(size uint32)
- func (s *Server) Stop()
- func (s *Server) Use(rf HandlerFunc)
Constants ¶
View Source
const ( GRACEFUL_ENVIRON_KEY = "IS_GRACEFUL" GRACEFUL_ENVIRON_STRING = GRACEFUL_ENVIRON_KEY + "=1" DEFAULT_READ_TIMEOUT = 60 * time.Second DEFAULT_WRITE_TIMEOUT = DEFAULT_READ_TIMEOUT )
View Source
const ( RED = uint8(iota + 91) GREEN YELLOW BLUE MAGENTA INFO = "[INFO]" TRAC = "[TRAC]" ERROR = "[ERROR]" WARN = "[WARNING]" SUCCESS = "[SUCCESS]" )
View Source
const ( DEV = "dev" PRODUCTION = "production" )
Variables ¶
This section is empty.
Functions ¶
func CloseClient ¶
踢掉一个连接并发送消息
func SendToClient ¶
给给定的客户端发送消息
Types ¶
type Connection ¶
type Connection struct { //连接的套接字 Conn *net.TCPConn //连接的ID ConnID uint32 //写通道退出状态的channel ExitChan chan bool //当前连接的处理方法 Handles IHandler // contains filtered or unexported fields }
func (*Connection) DelProperty ¶
func (c *Connection) DelProperty(key string)
func (*Connection) GetProperty ¶
func (c *Connection) GetProperty(key string) (interface{}, error)
func (*Connection) SetPackProto ¶
func (c *Connection) SetPackProto(proto IPack)
func (*Connection) SetProperty ¶
func (c *Connection) SetProperty(key string, val interface{})
添加当前连接额外kye-value
func (*Connection) SetProtoPack ¶
func (c *Connection) SetProtoPack(proto IPack)
type HLog ¶
type HLog struct {
// contains filtered or unexported fields
}
var Log *HLog
func NewLogWithModel ¶
type Handler ¶
type Handler struct { Middlewares []HandlerFunc //中间件集合 // contains filtered or unexported fields }
func NewHandler ¶
func NewHandler() *Handler
type HandlerFunc ¶
type HandlerFunc func(request IRequest)
type IConnection ¶
type IConnection interface { Start() Stop() GetConn() *net.TCPConn GetID() uint32 RemoteAddr() net.Addr Send(data []byte) error SetProperty(key string, val interface{}) GetProperty(key string) (interface{}, error) DelProperty(key string) SetProtoPack(IPack) GetServer() IServer }
func NewConnection ¶
type IEvent ¶
type IEvent interface { OnMessage(IRequest) OnConnect(IConnection, string) //连接对象, clientId OnClose(IConnection, string) OnWorkerStart() }
type IHandler ¶
type IHandler interface { RunHandler(request IRequest) Before(HandlerFunc) After(HandlerFunc) Use(HandlerFunc) Abort() RunWorkPool() SendToTasks(rq IRequest) SetWorkPoolSize(size uint32) SetEventHandle(IEvent) }
type IManager ¶
type IManager interface { Add(con IConnection) Del(con IConnection) Get(id uint32) (IConnection, error) Num() int Clear() }
func NewManager ¶
func NewManager() IManager
type IRequest ¶
type IRequest interface { GetConnection() IConnection GetData() []byte GetID() uint32 GetLen() uint32 SetWorkId(uint32) GetWorkId() uint32 //获取客户端连接id,封装的地址及连接信息字符串 GetClientId() string // contains filtered or unexported methods }
func NewRequest ¶
func NewRequest(con IConnection, msg IMessage, rid *uint32, clientId string) IRequest
实例化,rid:全局请求id
type IServer ¶
type IServer interface { Run() Stop() Before(HandlerFunc) After(HandlerFunc) Use(HandlerFunc) Abort() SetWorkPoolSize(uint32) GetRid() *uint32 GetManager() IManager OverLoad(overloadHandler) SetMaxCon(uint32) OnStart(hookHandler) OnStop(hookHandler) SetEventHandle(IEvent) // contains filtered or unexported methods }
type Listener ¶ added in v1.0.2
type Listener struct { *net.TCPListener // contains filtered or unexported fields }
func NewListener ¶ added in v1.0.2
func NewListener(listener *net.TCPListener, server *Server) *Listener
type Server ¶
type Server struct { IP string Port int Conn *Listener IPVersion string Handles *Handler Version string // contains filtered or unexported fields }
func (*Server) GetManager ¶
func (*Server) SetEventHandle ¶
func (*Server) SetProtoPack ¶
Source Files
¶
Click to show internal directories.
Click to hide internal directories.