Skip to content

Commit 1ca15f8

Browse files
committed
bug fix: default config
1 parent 0111355 commit 1ca15f8

File tree

5 files changed

+34
-10
lines changed

5 files changed

+34
-10
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ You can get runnable program in the releases of this repository, which supports
2929

3030
![](https://i.loli.net/2021/05/15/oQM1yZ6pWm3AIEj.png)
3131

32-
You could use redis-cli or other redis client to connect godis server, which listens on 127.0.0.1:6379 on default mode.
32+
You could use redis-cli or other redis client to connect godis server, which listens on 0.0.0.0:6399 on default mode.
3333

3434
![](https://i.loli.net/2021/05/15/7WquEgonzY62sZI.png)
3535

README_CN.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Godis 的信息。
2727

2828
![](https://i.loli.net/2021/05/15/oQM1yZ6pWm3AIEj.png)
2929

30-
godis 默认监听 127.0.0.1:6379,可以使用 redis-cli 或者其它 redis 客户端连接 Godis 服务器。
30+
godis 默认监听 0.0.0.0:6399,可以使用 redis-cli 或者其它 redis 客户端连接 Godis 服务器。
3131

3232
![](https://i.loli.net/2021/05/15/7WquEgonzY62sZI.png)
3333

build-all.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
./build-darwin.sh
2+
./build-linux.sh
File renamed without changes.

cmd/main.go

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package main
22

33
import (
4-
_ "embed"
54
"fmt"
65
"github.com/hdt3213/godis/config"
76
"github.com/hdt3213/godis/lib/logger"
@@ -10,22 +9,45 @@ import (
109
"os"
1110
)
1211

13-
//go:embed banner.txt
14-
var banner string
12+
var banner = `
13+
______ ___
14+
/ ____/___ ____/ (_)____
15+
/ / __/ __ \/ __ / / ___/
16+
/ /_/ / /_/ / /_/ / (__ )
17+
\____/\____/\__,_/_/____/
18+
`
19+
20+
var defaultProperties = &config.ServerProperties{
21+
Bind: "0.0.0.0",
22+
Port: 6399,
23+
AppendOnly: false,
24+
AppendFilename: "",
25+
MaxClients: 1000,
26+
}
27+
28+
func fileExists(filename string) bool {
29+
info, err := os.Stat(filename)
30+
return err != nil && !info.IsDir()
31+
}
1532

1633
func main() {
1734
print(banner)
18-
configFilename := os.Getenv("CONFIG")
19-
if configFilename == "" {
20-
configFilename = "redis.conf"
21-
}
22-
config.SetupConfig(configFilename)
2335
logger.Setup(&logger.Settings{
2436
Path: "logs",
2537
Name: "godis",
2638
Ext: ".log",
2739
TimeFormat: "2006-01-02",
2840
})
41+
configFilename := os.Getenv("CONFIG")
42+
if configFilename == "" {
43+
if fileExists("redis.conf") {
44+
config.SetupConfig("redis.conf")
45+
} else {
46+
config.Properties = defaultProperties
47+
}
48+
} else {
49+
config.SetupConfig(configFilename)
50+
}
2951

3052
err := tcp.ListenAndServeWithSignal(&tcp.Config{
3153
Address: fmt.Sprintf("%s:%d", config.Properties.Bind, config.Properties.Port),

0 commit comments

Comments
 (0)