forked from omnilaboratory/obd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
obdserver.go
83 lines (71 loc) · 1.89 KB
/
obdserver.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
package main
import (
"github.com/lestrrat-go/file-rotatelogs"
"github.com/omnilaboratory/obd/proxy/rpc"
"io"
"log"
"net/http"
"os"
"strconv"
"time"
"github.com/omnilaboratory/obd/bean"
"github.com/omnilaboratory/obd/config"
"github.com/omnilaboratory/obd/lightclient"
"github.com/omnilaboratory/obd/service"
"github.com/omnilaboratory/obd/tool"
)
func initObdLog() {
_dir := "log"
_ = tool.PathExistsAndCreate(_dir)
path := "log/obdServer"
writer, err := rotatelogs.New(
path+".%Y%m%d%H%M.log",
rotatelogs.WithMaxAge(30*34*time.Hour),
rotatelogs.WithRotationTime(4*time.Hour),
)
if err != nil {
panic(err)
}
writers := []io.Writer{
os.Stdout,
writer,
}
fileAndStdoutWriter := io.MultiWriter(writers...)
log.SetOutput(fileAndStdoutWriter)
log.SetFlags(log.Ldate | log.Lmicroseconds | log.Lshortfile)
}
// gox compile https://blog.csdn.net/han0373/article/details/81391455
// gox -os "windows linux darwin" -arch amd64
// gox -os "linux" -arch amd64
func main() {
config.Init()
initObdLog()
//tracker
err := lightclient.ConnectToTracker()
if err != nil {
log.Println("because fail to connect to tracker, obd fail to start")
return
}
routersInit := lightclient.InitRouter()
addr := ":" + strconv.Itoa(config.ServerPort)
server := &http.Server{
Addr: addr,
Handler: routersInit,
ReadTimeout: config.ReadTimeout,
WriteTimeout: config.WriteTimeout,
MaxHeaderBytes: 1 << 20,
}
service.Start()
// Timer
service.ScheduleService.StartSchedule()
go rpc.StartGrpcServer()
log.Println("obd " + tool.GetObdNodeId() + " start in " + config.ChainNodeType)
log.Println("wsAddress: " + bean.CurrObdNodeInfo.WebsocketLink)
//https://blog.csdn.net/Binary2014/article/details/103919365
//server.ListenAndServeTLS()
//err = server.ListenAndServeTLS("cert.pem", "key.pem")
//if err != nil {
// log.Println(err)
//}
log.Fatal(server.ListenAndServe())
}