-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
54 lines (46 loc) · 992 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
51
52
53
54
package main
import (
"fmt"
"os"
"zedis/config"
"zedis/logger"
redisServer "zedis/redis/server"
"zedis/tcp"
)
var defaultConfig = &config.ServerConfig{
RunId: config.GenRandomRunID(40),
Bind: "0.0.0.0",
Port: 6379,
MaxClients: 100,
}
var banner = `
______ ___
/ /___ ____/ (_)____
/ / __ \/ __ / / ___/
/ / /_/ / /_/ / (__ )
/___/\____/\__,_/_/____/
`
func fileExists(filePath string) bool {
info, err := os.Stat(filePath)
return err == nil && !info.IsDir()
}
func main() {
print(banner)
logger.Setup(&logger.Settings{
Path: "logs",
Name: "zedis",
Ext: "log",
TimeFormat: "2006-01-02",
})
if fileExists("redis.yaml") {
config.SetupConfig("redis.yaml")
} else {
config.Config = defaultConfig
}
err := tcp.ListenAndServeWithSignal(&tcp.Config{
Address: fmt.Sprintf("%s:%d", config.Config.Bind, config.Config.Port),
}, redisServer.NewHandler())
if err != nil {
logger.Error(err)
}
}