-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
51 lines (44 loc) · 997 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
package main
import (
"GoMiniCache/config"
"GoMiniCache/lib/logger"
redishandler "GoMiniCache/resp/handler"
"GoMiniCache/tcp"
"fmt"
"os"
)
const configFile string = "GoMiniCache.conf"
var defaultProperties = &config.ServerProperties{
Bind: "0.0.0.0",
Port: 9999,
}
func fileExists(filename string) bool {
info, err := os.Stat(filename)
return err == nil && !info.IsDir()
}
func main() {
// 初始化日志配置
logger.Setup(&logger.Settings{
Path: "logs",
Name: "GoMiniCache",
Ext: "log",
TimeFormat: "2006-01-02",
})
// 初始化配置
if fileExists(configFile) {
config.SetupConfig(configFile)
} else {
config.Properties = defaultProperties
}
// 启动 GoMiniCache 的服务器
err := tcp.ListenAndServeWithSignal(
&tcp.Config{
Address: fmt.Sprintf("%s:%d",
config.Properties.Bind,
config.Properties.Port),
},
redishandler.MakeRespHandler()) // 选择使用 TCP 的处理逻辑
if err != nil {
logger.Error(err)
}
}