-
Notifications
You must be signed in to change notification settings - Fork 41
/
main.go
114 lines (93 loc) · 3.76 KB
/
main.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
package main
import (
"context"
"filscan_lotus/controllers"
"filscan_lotus/filscaner"
lotus_filscan "filscan_lotus/filscanproto"
"fmt"
"github.com/astaxie/beego/config"
"gitlab.forceup.in/dev-go/gosf/jsonrpc"
"go.uber.org/zap"
"net/http"
)
func main() {
// 初始化 logger 实例
rawLogger, err := zap.NewDevelopment(zap.Fields(zap.String("serive", "lotus_filscan")))
if err != nil {
panic(err)
}
//jsonrpc.AddCustomizeCORSHeader("sid", "token", "X-Force-Token", "X-Force-Key")
Logger := rawLogger.Sugar()
// 初始化 root mux
rootMux := jsonrpc.NewRootMux("", Logger)
// base server
baseMux := lotus_filscan.NewJSONRpcMuxForFilscan(Logger, &controllers.FilscanServer{})
filscaner := filscaner.FilscanerInst
tipsetMux := lotus_filscan.NewJSONRpcMuxForFilscanTipset(Logger, &controllers.FilscanTipset{})
msgMux := lotus_filscan.NewJSONRpcMuxForFilscanMessages(Logger, &controllers.FilscanMessages{})
accountMux := lotus_filscan.NewJSONRpcMuxForFilscanAccount(Logger, &controllers.FilscanAccount{})
peerMux := lotus_filscan.NewJSONRpcMuxForFilscanPeer(Logger, &controllers.FilscanPeer{})
miningMux := lotus_filscan.NewJSONRpcMuxForFilscanMining(Logger, filscaner)
tokenMux := lotus_filscan.NewJSONRpcMuxForFilscanToken(Logger, filscaner)
/*baseMux := forceup.NewJSONRpcMuxForForceUp(Logger, &service.ForceUpUserBaseServer{})
// 生成 FilScan API Group 用户端
userMux := forceup.NewJSONRpcMuxForForceUpUser(Logger, &service.ForceUpUserOnlineServer{})
userMux.Use(session.InjectLoginUser())
fileMux := forceup.NewJSONRpcMuxForForceUpFiles(Logger, &service.ForceUpUserOnlineFileServer{})
fileMux.Use(session.InjectLoginUser())
// 将 force API Group 注册到 root 中
adminBaseMux := forceup.NewJSONRpcMuxForForceAdmin(Logger, &service.ForceAdminBaseServer{})
adminListMux := forceup.NewJSONRpcMuxForForceAdminOnline(Logger, &service.ForceAdminListServer{})
adminListMux.Use(session.InjectLoginUser())
adminOperateMux := forceup.NewJSONRpcMuxForForceAdminOperate(Logger, &service.ForceAdminOperateServer{})
adminOperateMux.Use(session.InjectLoginUser())
// user 依赖 base
baseMux.AddSubs(userMux)
baseMux.AddSubs(fileMux)
baseMux.AddSubs(adminBaseMux)
baseMux.AddSubs(adminListMux)
baseMux.AddSubs(adminOperateMux)
*/
// 将 force API Group 注册到 root 中
//rootMux.AddSubs(baseMux)
//rootMux.AddSubs(adminBaseMux)
// 使用标准库中的 http.ServeMux 和 http.Server 构建最终的 http 服务
// 初始化一个空的 http.ServeMux
baseMux.AddSubs(tipsetMux)
baseMux.AddSubs(msgMux)
baseMux.AddSubs(accountMux)
baseMux.AddSubs(miningMux)
baseMux.AddSubs(tokenMux)
baseMux.AddSubs(peerMux)
rootMux.AddSubs(baseMux)
httpMux := http.NewServeMux()
// 将 rootMux 中携带的接口, 中间件, 子组等封装成 http.HandlerFunc 并注册到 http.ServeMux 上
jsonrpc.RegisterMux(httpMux, rootMux)
config_file := "conf/app.conf"
iniconf, err := config.NewConfig("ini", config_file)
// iniconf, err := config.NewConfig("ini", "conf/local.app.conf")
if err != nil {
panic(err)
}
httpport := iniconf.String("httpport")
//go metric.Run(context.Background(), metric.DefaultConfig)
listenAdd := iniconf.String("listenAdd")
httpServer := http.Server{
Addr: fmt.Sprintf("%s:%s", listenAdd, httpport),
Handler: httpMux,
}
controllers.Firstinit() //初始化
if err := filscaner.Init(context.TODO(), config_file, controllers.LotusApi); err != nil {
panic(err)
}
controllers.SetFilscaner(filscaner)
filscaner.Run()
controllers.Run() //SynLotus
Logger.Info(fmt.Sprintf("server will listen %s:%s", listenAdd, httpport))
// 开始监听并想向外提供服务
if err := httpServer.ListenAndServe(); err != nil {
Logger.Errorf("http server listen and serve error, cause=%v", err)
}
// todo: need a stop method...
// filscaner.Stop()
}