-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.go
82 lines (69 loc) · 1.72 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
package main
import (
"flag"
"net/http"
_ "net/http/pprof"
"os"
"runtime"
"strconv"
"time"
"github.com/rs/zerolog"
)
var (
log = initLogger()
buildTime string
)
func initLogger() zerolog.Logger {
return zerolog.
New(zerolog.ConsoleWriter{Out: os.Stdout, TimeFormat: time.DateTime}).
Level(zerolog.TraceLevel).
With().
Timestamp().
Logger()
}
func config4Server(fileName string) {
if err := initConfig(fileName); err != nil {
log.Fatal().Msgf("init config error: %v", err)
}
if err := initServer(); err != nil {
log.Fatal().Msgf("init server error: %v", err)
}
if err := InitDB(); err != nil {
log.Fatal().Msgf("init db error: %v", err)
}
}
func printBanner() {
log.Printf(`
________ _____
___ __ \_______ /_____________ ___ Rotom %d bit (%s/%s)
__ /_/ / __ \ __/ __ \_ __ '__ \ Port: %d, Pid: %d
_ _, _// /_/ / /_ / /_/ / / / / / / Build: %s
/_/ |_| \____/\__/ \____//_/ /_/ /_/
`,
strconv.IntSize, runtime.GOARCH, runtime.GOOS,
configGetPort(), os.Getpid(),
buildTime)
}
// RegisterAeLoop register main aeLoop event.
func RegisterAeLoop(server *Server) {
server.aeLoop.AddRead(server.fd, AcceptHandler, nil)
server.aeLoop.AddTimeEvent(AeNormal, 100, CronEvictExpired, nil)
if configGetAppendOnly() {
server.aeLoop.AddTimeEvent(AeNormal, 1000, CronSyncAOF, nil)
}
}
func main() {
var path string
var debug bool
flag.StringVar(&path, "conf", defaultConfigFileName, "config file path.")
flag.BoolVar(&debug, "debug", false, "run with debug mode.")
flag.Parse()
config4Server(path)
printBanner()
if debug {
go http.ListenAndServe(":6060", nil)
}
log.Info().Msg("rotom server is ready to accept.")
RegisterAeLoop(&server)
server.aeLoop.AeMain()
}