-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
59 lines (52 loc) · 1.18 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
package main
import (
"fmt"
"github.com/HildaM/GoKV/config"
"github.com/HildaM/GoKV/lib/logger"
"github.com/HildaM/GoKV/redis/server"
"github.com/HildaM/GoKV/tcp"
"os"
)
var banner = `
______ ___
/ ____/___ ____/ (_)____
/ / __/ __ \/ __ / / ___/
/ /_/ / /_/ / /_/ / (__ )
\____/\____/\__,_/_/____/
`
var defaultProperties = &config.ServerProperties{
Bind: "0.0.0.0",
Port: 6399,
AppendOnly: false,
AppendFilename: "",
MaxClients: 1000,
}
func fileExists(filename string) bool {
info, err := os.Stat(filename)
return err == nil && !info.IsDir()
}
func main() {
print(banner)
logger.Setup(&logger.Settings{
Path: "logs",
Name: "godis",
Ext: ".log",
TimeFormat: "2006-01-02",
})
configFilename := os.Getenv("CONFIG")
if configFilename == "" {
if fileExists("redis.conf") {
config.SetupConfig("redis.conf")
} else {
config.Properties = defaultProperties
}
} else {
config.SetupConfig(configFilename)
}
err := tcp.ListenAndServerWithSignal(&tcp.Config{
Address: fmt.Sprintf("%s:%d", config.Properties.Bind, config.Properties.Port),
}, server.MakeHandler())
if err != nil {
logger.Fatal(err)
}
}