forked from liangdas/mqant
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.go
76 lines (64 loc) · 1.46 KB
/
server.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package main
import (
"github.com/jarekzha/mqant"
"github.com/jarekzha/mqant/conf"
"github.com/jarekzha/mqant/examples/proto/examples/greeter"
"github.com/jarekzha/mqant/module"
basemodule "github.com/jarekzha/mqant/module/base"
)
type Greeter struct {
}
func (g *Greeter) Hello(in *greeter.Request) (out *greeter.Response, err error) {
out = &greeter.Response{
Msg: "success",
}
return
}
func (g *Greeter) Stream(in *greeter.Request) (out *greeter.Response, err error) {
return
}
func main() {
// 服务实例
app := mqant.CreateApp(
module.Debug(false),
)
// 配置加载
app.OnConfigurationLoaded(func(app module.App) {
})
s := &Server{}
app.Run(s)
}
type Server struct {
basemodule.BaseModule
version string
// 模块名字
Name string
}
// GetApp module.App
func (m *Server) GetApp() module.App {
return m.App
}
// OnInit() 初始化配置
func (s *Server) OnInit(app module.App, settings *conf.ModuleSettings) {
s.BaseModule.OnInit(s, app, settings)
srv := &Greeter{}
greeter.RegisterGreeterTcpHandler(&s.BaseModule, srv)
}
// Run() 运行服务
func (s *Server) Run(closeSig chan bool) {
//创建MongoDB连接实例
}
// 销毁服务
func (s *Server) OnDestroy() {
//一定别忘了继承
s.BaseModule.OnDestroy()
s.GetServer().OnDestroy()
}
// Version() 获取当前服务的代码版本
func (s *Server) Version() string {
//可以在监控时了解代码版本
return s.version
}
func (s *Server) GetType() string {
return "greeter"
}