-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
50 lines (46 loc) · 993 Bytes
/
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
package main
import (
"fmt"
"mygodis/config"
logger "mygodis/log"
"mygodis/server"
"mygodis/tcp"
"os"
)
var defaultProperties = &config.ServerProperties{
Bind: "0.0.0.0",
Port: 6379,
AppendOnly: false,
MaxClients: 1024,
}
func main() {
logger.Setup(&logger.Settings{
Path: "logs",
Name: "MYGODIS",
Ext: "log",
TimeFormat: "2023-03-03",
})
envConfig := os.Getenv("MYGODISCONFIG")
if envConfig == "" {
if fileExists("redis.conf") {
config.SetupConfig("redis.conf")
} else {
config.Properties = defaultProperties
}
} else {
config.SetupConfig(envConfig)
}
addr := fmt.Sprintf("%s:%d", config.Properties.Bind, config.Properties.Port)
tcpConfig := tcp.Config{
Address: addr,
}
handler := server.MakeHandler()
err := tcp.ListenAndServeWithSignal(&tcpConfig, handler)
if err != nil {
logger.Error(err)
}
}
func fileExists(filename string) bool {
info, err := os.Stat(filename)
return err == nil && !info.IsDir()
}