Documentation
¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Handler ¶
type Handler interface {
connection.CallBack
OnConnect(c *connection.Connection)
}
Handler:Server 注册接口
type Options ¶
type Options struct {
Network string // 网络协议
Address string // 监听端口地址
NumLoops int // work 协程个数,负责处理已连接客户端的读写事件
ReusePort bool // 是否开启端口复用
IdleTime time.Duration // 最大空闲时间(秒)
Protocol connection.Protocol // 连接协议
// contains filtered or unexported fields
}
Options:服务配置
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server:fastnet Server
func (*Server) RunAfter ¶
func (s *Server) RunAfter(d time.Duration, f func()) *timingwheel.Timer
RunAfter:延时任务开启
Example ¶
handler := new(example)
s, err := NewServer(handler,
Network("tcp"),
Address(":1833"),
NumLoops(8),
ReusePort(true))
if err != nil {
panic(err)
}
go s.Start()
defer s.Stop()
s.RunAfter(time.Second, func() {
fmt.Println("RunAfter")
})
time.Sleep(2500 * time.Millisecond)
Output: RunAfter
func (*Server) RunEvery ¶
func (s *Server) RunEvery(d time.Duration, f func()) *timingwheel.Timer
RunEvery:定时任务,定时每 Duration 时间执行 f
Example ¶
handler := new(example)
s, err := NewServer(handler,
Network("tcp"),
Address(":1833"),
NumLoops(8),
ReusePort(true))
if err != nil {
panic(err)
}
go s.Start()
defer s.Stop()
t := s.RunEvery(time.Second, func() {
fmt.Println("EveryFunc")
})
time.Sleep(4500 * time.Millisecond)
t.Stop()
time.Sleep(4500 * time.Millisecond)
Output: EveryFunc EveryFunc EveryFunc EveryFunc
Directories
¶
| Path | Synopsis |
|---|---|
|
benchmarks
|
|
|
client
command
|
|
|
net-echo-server
command
|
|
|
example
|
|
|
echo
command
|
|
|
maxconnection
command
|
|
|
protobuf/client
command
|
|
|
protobuf/server
command
|
|
|
protocol
command
|
|
|
protocol/client
command
|
|
|
pushmessage
command
|
|
|
websocket
command
|
|
|
Package log is from https://github.com/micro/go-micro/blob/master/util/log/log.go
|
Package log is from https://github.com/micro/go-micro/blob/master/util/log/log.go |
|
plugins
|
|
|
tool
|
|
Click to show internal directories.
Click to hide internal directories.