Skip to content

Commit d2e4950

Browse files
committed
fix: yaml not working
1 parent e64965f commit d2e4950

File tree

7 files changed

+43
-14
lines changed

7 files changed

+43
-14
lines changed

CONTRIBUTION.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ Run with given config file:
44

55
```shell
66
APP=flydav ARGS="-c /etc/flydav/flydav.toml" make run
7-
```
7+
```

cmd/flydav/app/logger.go

+7
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,19 @@ import (
1111
)
1212

1313
func InitLogger(cnf conf.Log, verbose bool) {
14+
if(verbose){
15+
println("verbose mode enabled")
16+
}
1417
newLoggerCount := len(cnf.Stdout) + len(cnf.File)
1518
if newLoggerCount != 0 {
1619
for i := 0; i < newLoggerCount; i++ {
1720
logger.AddLogger(logrus.New())
1821
}
1922
} else {
2023
// if no logger configured, use default logger
24+
if(verbose){
25+
println("no logger configured, use default logger")
26+
}
2127
logger.SetOutput(os.Stdout)
2228
return
2329
}
@@ -28,6 +34,7 @@ func InitLogger(cnf conf.Log, verbose bool) {
2834
// enable source code line numbers
2935
logger.SetReportCaller(true)
3036
} else {
37+
println("Verbose mode disabled")
3138
logger.SetLevel(levelToLogrusLevel(cnf.Level))
3239
}
3340

cmd/flydav/conf/conf.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func GetDefaultConf() Conf {
4141
{
4242
Username: "flydav",
4343
PasswordHash: (func() string {
44-
b, _ := bcrypt.GenerateFromPassword([]byte("flydav"), bcrypt.DefaultCost)
44+
b, _ := bcrypt.GenerateFromPassword([]byte("flydavdefaultpassword"), bcrypt.DefaultCost)
4545
return string(b)
4646
})(),
4747
PasswordCrypt: BcryptHash,

cmd/flydav/main.go

+32-8
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,14 @@ func main() {
2525
var defaultConf = conf.GetDefaultConf()
2626

2727
args = loadArgsValid()
28-
cnf = loadConfValid(args.Config, defaultConf, "config.toml")
28+
if args.Verbose {
29+
fmt.Printf("args: %+v\n", args)
30+
}
31+
32+
cnf = loadConfValid(args.Verbose, args.Config, defaultConf, "config.toml")
33+
if args.Verbose {
34+
fmt.Printf("conf: %+v\n", cnf)
35+
}
2936
overrideConf(&cnf, args)
3037
validateConf(&cnf)
3138
app.InitLogger(cnf.Log, args.Verbose)
@@ -103,20 +110,29 @@ func getAppDir() string {
103110
return filepath.Dir(dir)
104111
}
105112

106-
func loadConfValid(path string, defaultConf conf.Conf, defaultConfPath string) conf.Conf {
113+
func loadConfValid(verbose bool, path string, defaultConf conf.Conf, defaultConfPath string) conf.Conf {
107114
if path == "" {
108115
path = defaultConfPath
116+
if verbose {
117+
fmt.Println("no config file specified, using default config file: ", path)
118+
}
109119
}
110120
// app executable dir + config.toml has the highest priority
111121
preferredPath := filepath.Join(getAppDir(), path)
112122
if _, err := os.Stat(preferredPath); err == nil {
113123
path = preferredPath
124+
if verbose {
125+
fmt.Println("using config file: ", path)
126+
}
114127
}
128+
115129
err := decode(path, &defaultConf)
116-
if err != nil {
117-
logger.Warn("failed to load config file: ", err, " using default config")
130+
if err != nil && verbose {
131+
os.Stderr.WriteString(fmt.Sprintf("Failed to load config file: %s\n", err))
132+
}else
133+
{
134+
logger.WithField("conf", &defaultConf).Debug("configuration loaded")
118135
}
119-
logger.WithField("conf", &defaultConf).Debug("configuration loaded")
120136
return defaultConf
121137
}
122138

@@ -127,10 +143,18 @@ func decode(path string, conf *conf.Conf) (error) {
127143
}
128144

129145
switch ext {
130-
case ".toml":
146+
case "toml":
131147
_, err = toml.DecodeFile(path, conf)
132-
case ".yaml", ".yml":
133-
err = yaml.Unmarshal([]byte(path), conf)
148+
case "yaml", "yml":
149+
content, err := os.ReadFile(path)
150+
if err != nil {
151+
return fmt.Errorf("failed to read config file: %s", err)
152+
}
153+
154+
err = yaml.Unmarshal([]byte(content), conf)
155+
if err != nil {
156+
return fmt.Errorf("failed to parse config file: %s", err)
157+
}
134158
default:
135159
err = fmt.Errorf("unsupported config file extension: %s", ext)
136160
}

conf/config.default.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
server:
22
host: 0.0.0.0
3-
port: 7086
3+
port: 7000
44
path: /webdav
55
fs_dir: /tmp/flydav
66
ui:

scripts/installer.sh

-2
Original file line numberDiff line numberDiff line change
@@ -327,5 +327,3 @@ echo "Starting systemd service"
327327
must_run systemctl start flydav.service
328328

329329
echo "Installation complete"
330-
331-

scripts/ui_installer.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -139,4 +139,4 @@ must_run unzip /tmp/flydav_install/flydav-ui-dist.zip -d $UI_INSTALL_DIR
139139
echo "Flydav UI is installed to $UI_INSTALL_DIR"
140140
echo "Edit your flydav config file and restart to enable UI"
141141

142-
clean_up
142+
clean_up

0 commit comments

Comments
 (0)