-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
62 lines (55 loc) · 1.28 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
58
59
60
61
62
package main
import (
"fmt"
"github.com/xuning888/godis-tiny/config"
"github.com/xuning888/godis-tiny/pkg/logger"
"github.com/xuning888/godis-tiny/pkg/util"
"github.com/xuning888/godis-tiny/redis"
"os"
)
var serverName = "godis-tiny"
var defaultConfig = &config.ServerProperties{
Bind: "0.0.0.0",
Port: 6389,
AppendOnly: false,
AppendFilename: "",
RunID: util.RandStr(40),
}
func fileExists(filename string) bool {
stat, err := os.Stat(filename)
return err == nil && !stat.IsDir()
}
func setupConfiguration(configPath string) {
if fileExists(configPath) {
config.SetUpConfig(configPath)
logger.Infof("Loaded configuration from %s", configPath)
} else {
logger.Infof("Config file '%s' not found. Using default settings.", configPath)
config.Properties = defaultConfig
}
}
func printHelp() {
helpText := `Usage: ./` + serverName + ` [/path/to/redis.conf] [options] [-]
./` + serverName + ` -h or --help
`
fmt.Print(helpText)
}
func main() {
logger.InitLogger()
args := os.Args[1:]
if len(args) > 0 {
for _, arg := range args {
switch arg {
case "-h", "--help":
printHelp()
return
default:
setupConfiguration(arg)
}
}
} else {
setupConfiguration("redis.conf")
}
s := redis.NewRedisServer()
s.Spin()
}