fix: config issue

This commit is contained in:
Marvin Zhang
2024-07-10 18:39:39 +08:00
parent 4da8976228
commit e64ffb3dec
3 changed files with 31 additions and 51 deletions

View File

@@ -1,3 +1,27 @@
info: # Crawlab Configuration File
edition: global.edition.community edition: global.edition.community
version: v0.6.3 version: v0.6.3
mongo:
host: localhost
port: 27017
db: crawlab_test
username: ""
password: ""
authSource: "admin"
server:
host: 0.0.0.0
port: 8000
grpc:
address: localhost:9666
server:
address: 0.0.0.0:9666
authKey: Crawlab2021!
api:
endpoint: http://localhost:8000
log:
path: /var/log/crawlab

View File

@@ -1,7 +1,6 @@
package config package config
import ( import (
"bytes"
"github.com/apex/log" "github.com/apex/log"
"github.com/crawlab-team/crawlab/trace" "github.com/crawlab-team/crawlab/trace"
"github.com/fsnotify/fsnotify" "github.com/fsnotify/fsnotify"
@@ -63,14 +62,10 @@ func (c *Config) Init() (err error) {
replacer := strings.NewReplacer(".", "_") replacer := strings.NewReplacer(".", "_")
viper.SetEnvKeyReplacer(replacer) viper.SetEnvKeyReplacer(replacer)
// read default config // read in config
defaultConfBuf := bytes.NewBufferString(DefaultConfigYaml) if err := viper.ReadInConfig(); err != nil {
if err := viper.ReadConfig(defaultConfBuf); err != nil { log.Errorf("Error reading config file, %s", err)
return trace.TraceError(err) trace.PrintError(err)
}
// merge config
if err := viper.MergeInConfig(); err != nil { // viper parsing config file
return err return err
} }

View File

@@ -1,39 +0,0 @@
package config
var DefaultConfigYaml = `
version: v0.6.3
edition: global.edition.community
mongo:
host: localhost
port: 27017
db: crawlab_test
username: ""
password: ""
authSource: "admin"
server:
host: 0.0.0.0
port: 8000
spider:
fs: "/spiders"
workspace: "/workspace"
repo: "/repo"
task:
workers: 16
cancelWaitSeconds: 30
grpc:
address: localhost:9666
server:
address: 0.0.0.0:9666
authKey: Crawlab2021!
fs:
filer:
proxy: http://localhost:8888
url: http://localhost:8000/filer
authKey: Crawlab2021!
node:
master: Y
api:
endpoint: http://localhost:8000
log:
path: /var/log/crawlab
`