Documentation
¶
Overview ¶
---------------------------------------------------------------------//
GNU GENERAL PUBLIC LICENSE //
Version 2, June 1991 //
//
Copyright (C) Wells Hsu, wellshsu@outlook.com, All rights reserved. // Everyone is permitted to copy and distribute verbatim copies // of this license document, but changing it is not allowed. //
SEE LICENSE.md FOR MORE DETAILS. //
---------------------------------------------------------------------//
---------------------------------------------------------------------//
GNU GENERAL PUBLIC LICENSE //
Version 2, June 1991 //
//
Copyright (C) Wells Hsu, wellshsu@outlook.com, All rights reserved. // Everyone is permitted to copy and distribute verbatim copies // of this license document, but changing it is not allowed. //
SEE LICENSE.md FOR MORE DETAILS. //
---------------------------------------------------------------------//
---------------------------------------------------------------------//
GNU GENERAL PUBLIC LICENSE //
Version 2, June 1991 //
//
Copyright (C) Wells Hsu, wellshsu@outlook.com, All rights reserved. // Everyone is permitted to copy and distribute verbatim copies // of this license document, but changing it is not allowed. //
SEE LICENSE.md FOR MORE DETAILS. //
---------------------------------------------------------------------//
---------------------------------------------------------------------//
GNU GENERAL PUBLIC LICENSE //
Version 2, June 1991 //
//
Copyright (C) Wells Hsu, wellshsu@outlook.com, All rights reserved. // Everyone is permitted to copy and distribute verbatim copies // of this license document, but changing it is not allowed. //
SEE LICENSE.md FOR MORE DETAILS. //
---------------------------------------------------------------------//
---------------------------------------------------------------------//
GNU GENERAL PUBLIC LICENSE //
Version 2, June 1991 //
//
Copyright (C) Wells Hsu, wellshsu@outlook.com, All rights reserved. // Everyone is permitted to copy and distribute verbatim copies // of this license document, but changing it is not allowed. //
SEE LICENSE.md FOR MORE DETAILS. //
---------------------------------------------------------------------//
---------------------------------------------------------------------//
GNU GENERAL PUBLIC LICENSE //
Version 2, June 1991 //
//
Copyright (C) Wells Hsu, wellshsu@outlook.com, All rights reserved. // Everyone is permitted to copy and distribute verbatim copies // of this license document, but changing it is not allowed. //
SEE LICENSE.md FOR MORE DETAILS. //
---------------------------------------------------------------------//
---------------------------------------------------------------------//
GNU GENERAL PUBLIC LICENSE //
Version 2, June 1991 //
//
Copyright (C) Wells Hsu, wellshsu@outlook.com, All rights reserved. // Everyone is permitted to copy and distribute verbatim copies // of this license document, but changing it is not allowed. //
SEE LICENSE.md FOR MORE DETAILS. //
---------------------------------------------------------------------//
---------------------------------------------------------------------//
GNU GENERAL PUBLIC LICENSE //
Version 2, June 1991 //
//
Copyright (C) Wells Hsu, wellshsu@outlook.com, All rights reserved. // Everyone is permitted to copy and distribute verbatim copies // of this license document, but changing it is not allowed. //
SEE LICENSE.md FOR MORE DETAILS. //
---------------------------------------------------------------------//
---------------------------------------------------------------------//
GNU GENERAL PUBLIC LICENSE //
Version 2, June 1991 //
//
Copyright (C) Wells Hsu, wellshsu@outlook.com, All rights reserved. // Everyone is permitted to copy and distribute verbatim copies // of this license document, but changing it is not allowed. //
SEE LICENSE.md FOR MORE DETAILS. //
---------------------------------------------------------------------//
---------------------------------------------------------------------//
GNU GENERAL PUBLIC LICENSE //
Version 2, June 1991 //
//
Copyright (C) Wells Hsu, wellshsu@outlook.com, All rights reserved. // Everyone is permitted to copy and distribute verbatim copies // of this license document, but changing it is not allowed. //
SEE LICENSE.md FOR MORE DETAILS. //
---------------------------------------------------------------------//
---------------------------------------------------------------------//
GNU GENERAL PUBLIC LICENSE //
Version 2, June 1991 //
//
Copyright (C) Wells Hsu, wellshsu@outlook.com, All rights reserved. // Everyone is permitted to copy and distribute verbatim copies // of this license document, but changing it is not allowed. //
SEE LICENSE.md FOR MORE DETAILS. //
---------------------------------------------------------------------//
---------------------------------------------------------------------//
GNU GENERAL PUBLIC LICENSE //
Version 2, June 1991 //
//
Copyright (C) Wells Hsu, wellshsu@outlook.com, All rights reserved. // Everyone is permitted to copy and distribute verbatim copies // of this license document, but changing it is not allowed. //
SEE LICENSE.md FOR MORE DETAILS. //
---------------------------------------------------------------------//
---------------------------------------------------------------------//
GNU GENERAL PUBLIC LICENSE //
Version 2, June 1991 //
//
Copyright (C) Wells Hsu, wellshsu@outlook.com, All rights reserved. // Everyone is permitted to copy and distribute verbatim copies // of this license document, but changing it is not allowed. //
SEE LICENSE.md FOR MORE DETAILS. //
---------------------------------------------------------------------//
---------------------------------------------------------------------//
GNU GENERAL PUBLIC LICENSE //
Version 2, June 1991 //
//
Copyright (C) Wells Hsu, wellshsu@outlook.com, All rights reserved. // Everyone is permitted to copy and distribute verbatim copies // of this license document, but changing it is not allowed. //
SEE LICENSE.md FOR MORE DETAILS. //
---------------------------------------------------------------------//
---------------------------------------------------------------------//
GNU GENERAL PUBLIC LICENSE //
Version 2, June 1991 //
//
Copyright (C) Wells Hsu, wellshsu@outlook.com, All rights reserved. // Everyone is permitted to copy and distribute verbatim copies // of this license document, but changing it is not allowed. //
SEE LICENSE.md FOR MORE DETAILS. //
---------------------------------------------------------------------//
---------------------------------------------------------------------//
GNU GENERAL PUBLIC LICENSE //
Version 2, June 1991 //
//
Copyright (C) Wells Hsu, wellshsu@outlook.com, All rights reserved. // Everyone is permitted to copy and distribute verbatim copies // of this license document, but changing it is not allowed. //
SEE LICENSE.md FOR MORE DETAILS. //
---------------------------------------------------------------------//
Index ¶
- Constants
- Variables
- func BackupLan() int
- func ClearInterval(id int, tid ...int64)
- func ClearTimeout(id int, tid ...int64)
- func CloseLan()
- func MonitorLan()
- func NotifyCgi(id int, req *xproto.CgiReq, resp *xproto.CgiResp) bool
- func NotifyEvt(id int, param interface{}) bool
- func NotifyMsg(id int, mreq *xproto.MsgReq) bool
- func NotifyRpc(id int, req *xproto.RpcReq, resp *xproto.RpcResp) bool
- func PauseLan()
- func PostKV(key string, value string, version string, block ...bool) bool
- func PullKV(key string) []byte
- func RecvLan()
- func RegCgi(id int, fun func(req *xproto.CgiReq, resp *xproto.CgiResp)) int
- func RegCgiRoute(_map map[int]*CgiRoute)
- func RegEvt(id int, fun func(interface{})) int
- func RegMsg(id int, fun func(*xproto.MsgReq)) int
- func RegMsgRoute(_map map[int]*MsgRoute)
- func RegRpc(id int, fun func(rreq *xproto.RpcReq, rresp *xproto.RpcResp)) int
- func RegRpcRoute(_map map[int]*RpcRoute)
- func RestoreLan()
- func ResumeLan()
- func RunIn(tid int64, fun func()) chan bool
- func RunInMain(fun func()) chan bool
- func SendAsync(id int, uid int, req proto.Message, addr string, ...)
- func SendCgi(id int, uid int, req *http.Request, addr string, timeout ...int) (cresp *xproto.CgiResp, err error)
- func SendFrame(frame xproto.IFrame) bool
- func SendMsg(id int, msg proto.Message, mreq *xproto.MsgReq) bool
- func SendSync(id int, uid int, req proto.Message, resp proto.Message, addr string, ...) error
- func Start(svr IServer)
- func StartLan(lanCfg *LanCfg, handleMsg func(*xproto.MsgReq), ...)
- func Stop()
- func SubKV(key string, interval int, onUpdate func(data []byte))
- func UnregCgi(id int, hid int) bool
- func UnregEvt(id int, hid int) bool
- func UnregMsg(id int, hid int) bool
- func UnregRpc(id int, hid int) bool
- func WatchSignal() <-chan string
- type CgiFunc
- type CgiRoute
- type EvtFunc
- type IServer
- type LanCfg
- type LanClt
- type LanSvr
- type MsgFunc
- type MsgRoute
- type Proc
- type Route
- type RpcFunc
- type RpcRoute
- type Server
- func (this *Server) CTOR(CHILD interface{})
- func (this *Server) Destroy()
- func (this *Server) GetConfig() *SvrCfg
- func (this *Server) GetFPS() int
- func (this *Server) GetTitle() string
- func (_this *Server) Init() bool
- func (this *Server) InitConfig() bool
- func (this *Server) Name() string
- func (_this *Server) PreQuit()
- func (this *Server) RecvCgi(rreq *xproto.CgiReq, rresp *xproto.CgiResp)
- func (this *Server) RecvMsg(mreq *xproto.MsgReq)
- func (this *Server) RecvRpc(rreq *xproto.RpcReq, rresp *xproto.RpcResp)
- func (this *Server) Start()
- func (this *Server) Update(delta float32)
- func (this *Server) UpdateTitle() string
- type SvrCfg
- type TimerEntity
- type TimerRecord
- type Wrap
Constants ¶
const ( CONSUL_RESP_OK = "ok" // Consul响应200 CONSUL_CHECK_PATH = "/check" // Consul心跳检测 )
const ( LAN_CIN_MAX_FRAME = 50000 LAN_COUT_MAX_FRAME = 50000 )
const ( EVT_SERVER_STARTED = -1 // 服务就绪(配置就绪 & 日志就绪 & DB就绪 & Redis就绪 & Lan就绪) EVT_SERVER_CHANGED = -2 // 服务变更(参数类型:[]interface{}{added map[string][]string, removed map[string][]string}) EVT_SERVER_PREQUIT = -3 // 服务即将退出 )
const (
SERVER_SLEEP time.Duration = 10 * time.Millisecond
)
const (
UPDATE_SLEEP time.Duration = 10 * time.Millisecond
)
Variables ¶
var ( CslClt *consulapi.Client // Consul连接 CslCfg *consulapi.Config // Consul配置 )
var ( GMsg = xevt.NewEvtMgr(true) // Msg消息中心 GRpc = xevt.NewEvtMgr(false) // Rpc消息中心 GCgi = xevt.NewEvtMgr(false) // Cgi消息中心 GEvt = xevt.NewEvtMgr(true) // Evt消息中心 )
var ( ERR_SEND_CHAN_FULL = errors.New("send chan is full") ERR_NO_ROUTE_FOUND = errors.New("no route found") ERR_RPC_TIMEOUT = errors.New("rpc call timeout") ERR_CGI_TIMEOUT = errors.New("cgi call timeout") ERR_RPC_INTERRUPTED = errors.New("rpc call has been interrupted, see log context for more details.") ERR_CGI_INTERRUPTED = errors.New("cgi call has been interrupted, see log context for more details.") )
var ( GWrap *Wrap GServer IServer )
var CGIROUTEMAP map[int]*CgiRoute // cgi路由
var MSGROUTEMAP map[int]*MsgRoute // msg路由
var (
MainTID int64 = -1
)
var RPCROUTEMAP map[int]*RpcRoute // rpc路由
Functions ¶
func MonitorLan ¶
func MonitorLan()
func RegCgiRoute ¶
func RegMsgRoute ¶
func RegRpcRoute ¶
func RestoreLan ¶
func RestoreLan()
func SendAsync ¶
func SendAsync(id int, uid int, req proto.Message, addr string, callback func(frame *xproto.RpcResp, err error), offsetAndTimeout ...int)
[发送Rpc消息(异步)] [id-消息ID] [uid-用户ID(负载均衡)] [req-请求结构体] [addr-目标服务器] [callback-回调函数] [offset-目标协程ID偏移(基于protocol中定义)] [timeout-超时时长]
func SendCgi ¶
func SendCgi(id int, uid int, req *http.Request, addr string, timeout ...int) (cresp *xproto.CgiResp, err error)
[发送Cgi消息(同步,否则ResponseWriter无法输出)] [id-消息ID] [uid-用户ID(负载均衡)] [req-请求结构体] [addr-目标服务器] [timeout-超时时长]
func SendSync ¶
func SendSync(id int, uid int, req proto.Message, resp proto.Message, addr string, offsetAndTimeout ...int) error
[发送Rpc消息(同步)] [id-消息ID] [uid-用户ID(负载均衡)] [req-请求结构体] [resp-返回结构体] [addr-目标服务器] [offset-目标协程偏移(基于protocol中定义)] [timeout-超时时长]
func WatchSignal ¶
func WatchSignal() <-chan string
Types ¶
type IServer ¶
type IServer interface {
Init() bool // 初始化
Start() // 服务启动
Update(delta float32) // 服务循环
Destroy() // 服务结束
PreQuit() // 服务即将退出
Name() string // 服务名称
InitConfig() bool // 读取配置
GetConfig() *SvrCfg // 获取配置
GetFPS() int // 获取帧率
UpdateTitle() string // 更新标题
GetTitle() string // 获取标题
RecvMsg(mreq *xproto.MsgReq) // 接收Msg消息
RecvRpc(rreq *xproto.RpcReq, rresp *xproto.RpcResp) // 接收Rpc消息
RecvCgi(creq *xproto.CgiReq, cresp *xproto.CgiResp) // 接收Cgi消息
}
type LanCfg ¶
type LanSvr ¶
type LanSvr struct {
*LanCfg
mangos.Socket
Clients sync.Map // map[string][]*LanClt
ClientID sync.Map // map[string]*LanClt
SClosed bool
}
func (*LanSvr) SelectRand ¶
type Proc ¶
type Route ¶
type Server ¶
func (*Server) UpdateTitle ¶
type SvrCfg ¶
type SvrCfg struct {
Raw xconfig.Configer
Env string // 环境标识: 测试,内测,生产
LanCfg *LanCfg
LinkServer string // 需要连接的内部服务器
ConsulAddr string // Consul中心地址
ConsulHttp string // Consul检测地址
ConsulTimeout string // Consul超时时间
ConsulInterval string // Consul访问间隔
ConsulDeregister string // Consul延迟注销
}
func (*SvrCfg) IsDebugEnv ¶
type TimerEntity ¶
type TimerEntity struct {
ID int
Func func()
Time int
RawTime int
Repeat bool
Crash bool
RW bool
Tag interface{}
Log int
}
func SetInterval ¶
func SetInterval(fun func(), interval float32, tid ...int64) *TimerEntity
设置间歇调用(周期以秒为单位)(务必在逻辑线程中调用或指定线程ID[tid])
func SetTimeout ¶
func SetTimeout(fun func(), timeout float32, tid ...int64) *TimerEntity
设置超时调用(时间以秒为单位)(务必在逻辑线程中调用或指定线程ID[tid])
type TimerRecord ¶
func (*TimerRecord) MaxID ¶
func (this *TimerRecord) MaxID() int64