-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
57 lines (52 loc) · 1.23 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
// Package main -----------------------------
// @file : main.go
// @author : hcjjj
// @contact : [email protected]
// @time : 2023/12/15 20:23
// -------------------------------------------
package main
import (
"fmt"
"os"
"redis-go/lib/config"
"redis-go/lib/logger"
"redis-go/resp/handler"
"redis-go/tcp"
)
const configFile string = "redis.conf"
var defaultProperties = &config.ServerProperties{
Bind: "0.0.0.0",
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: "redis-go",
Ext: "log",
TimeFormat: "2023-12-15",
})
if fileExists(configFile) {
config.SetupConfig(configFile)
} else {
// 如果没有配置文件
// 这样子就是单机模式了
config.Properties = defaultProperties
}
logger.Info(fmt.Sprintf("%s:%d", config.Properties.Bind, config.Properties.Port))
// 业务
err := tcp.ListenAndServeWithSignal(
&tcp.Config{
// IP:PORT
Address: fmt.Sprintf("%s:%d", config.Properties.Bind, config.Properties.Port),
},
//tcp.MakeEchoHandler())
handler.MakeHandler())
if err != nil {
logger.Error(err)
}
}