-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
50 lines (44 loc) · 950 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"
"go-redis/config"
"go-redis/lib/logger"
"go-redis/resp/handler"
"go-redis/tcp"
"os"
)
const configFile string = "redis.conf"
var defaultProperties = &config.ServerProperties{
Bind: "127.0.0.1",
Port: 6379,
}
func fileExists(fileName string) bool {
info, err := os.Stat(fileName)
return err == nil && !info.IsDir()
}
func main() {
// 设置日志框架
logger.Setup(&logger.Settings{
Path: "logs",
Name: "go-redis",
Ext: "log",
TimeFormat: "2003-03-19",
})
// 判断配置文件是否存在
if fileExists(configFile) {
config.SetupConfig(configFile)
} else {
config.Properties = defaultProperties
}
err := tcp.ListenAndServeWithSignal(
&tcp.Config{
Address: fmt.Sprintf("%s:%d", config.Properties.Bind, config.Properties.Port),
},
// 更换为resp的handler
//tcp.MakeEchoHandler(),
handler.MakeRespHandler(),
)
if err != nil {
logger.Error(err)
}
}