Skip to content

Commit a27ac80

Browse files
committed
fix: config no such file or directory
1 parent 8e630da commit a27ac80

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

internal/app/app.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ func Run() {
2121

2222
config, err := config.Load(*configPath)
2323
if err != nil {
24-
panic(err)
24+
log.Fatal(err.Error())
2525
}
2626

2727
pendingUpdateCount := prometheus.NewGauge(prometheus.GaugeOpts{

internal/config/config.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package config
33
import (
44
"errors"
55
"io/ioutil"
6+
"log"
67
"os"
78
"path/filepath"
89

@@ -36,19 +37,18 @@ func Load(configPath string) (*Config, error) {
3637
filename, _ := filepath.Abs(configPath)
3738
yamlFile, err := ioutil.ReadFile(filename)
3839
if err != nil {
39-
return nil, err
40-
}
41-
42-
// var config model.Config
43-
err = yaml.Unmarshal(yamlFile, &config)
44-
if err != nil {
45-
return nil, err
40+
log.Print(err.Error(), ", try to start with default configs")
41+
} else {
42+
err = yaml.Unmarshal(yamlFile, &config)
43+
if err != nil {
44+
return nil, err
45+
}
4646
}
4747

4848
if envBotToken := os.Getenv("BOT_TOKEN"); envBotToken != "" {
4949
config.Telegram.Token = envBotToken
5050
} else if config.Telegram.Token == "" {
51-
return nil, errors.New("Telegram Token is missing in " + configPath)
51+
return nil, errors.New("Telegram Token is missing")
5252
}
5353

5454
return &config, nil

0 commit comments

Comments
 (0)