mirror of
https://github.com/terorie/od-database-crawler.git
synced 2025-04-18 18:06:45 +00:00
Better config
This commit is contained in:
parent
ddfdce9d0f
commit
c196b6f20d
38
config.go
38
config.go
@ -11,22 +11,25 @@ var config struct {
|
||||
Token string
|
||||
Retries int
|
||||
Workers int
|
||||
Tasks int
|
||||
StatsInterval time.Duration
|
||||
Verbose bool
|
||||
}
|
||||
|
||||
const (
|
||||
ConfServerUrl = "server_url"
|
||||
ConfToken = "token"
|
||||
ConfRetries = "retries"
|
||||
ConfWorkers = "workers"
|
||||
ConfStatsInterval = "stats_interval"
|
||||
ConfVerbose = "verbose"
|
||||
ConfServerUrl = "server.url"
|
||||
ConfToken = "server.token"
|
||||
ConfTasks = "crawl.tasks"
|
||||
ConfRetries = "crawl.retries"
|
||||
ConfWorkers = "crawl.connections"
|
||||
ConfStatsInterval = "output.stats_interval"
|
||||
ConfVerbose = "output.verbose"
|
||||
)
|
||||
|
||||
func prepareConfig() {
|
||||
viper.SetDefault(ConfRetries, 3)
|
||||
viper.SetDefault(ConfWorkers, 50)
|
||||
viper.SetDefault(ConfRetries, 5)
|
||||
viper.SetDefault(ConfWorkers, 2)
|
||||
viper.SetDefault(ConfTasks, 3)
|
||||
viper.SetDefault(ConfStatsInterval, 3 * time.Second)
|
||||
viper.SetDefault(ConfVerbose, false)
|
||||
}
|
||||
@ -41,12 +44,12 @@ func readConfig() {
|
||||
|
||||
config.ServerUrl = viper.GetString(ConfServerUrl)
|
||||
if config.ServerUrl == "" {
|
||||
logrus.Fatal("config: server_url not set!")
|
||||
configMissing(ConfServerUrl)
|
||||
}
|
||||
|
||||
config.Token = viper.GetString(ConfToken)
|
||||
if config.Token == "" {
|
||||
logrus.Fatal("config: token not set!")
|
||||
configMissing(ConfToken)
|
||||
}
|
||||
|
||||
config.Retries = viper.GetInt(ConfRetries)
|
||||
@ -56,7 +59,12 @@ func readConfig() {
|
||||
|
||||
config.Workers = viper.GetInt(ConfWorkers)
|
||||
if config.Workers <= 0 {
|
||||
logrus.Fatal("config: illegal value %d for workers!", config.Workers)
|
||||
configOOB(ConfWorkers, config.Workers)
|
||||
}
|
||||
|
||||
config.Tasks = viper.GetInt(ConfTasks)
|
||||
if config.Tasks <= 0 {
|
||||
configOOB(ConfTasks, config.Tasks)
|
||||
}
|
||||
|
||||
config.StatsInterval = viper.GetDuration(ConfStatsInterval)
|
||||
@ -66,3 +74,11 @@ func readConfig() {
|
||||
logrus.SetLevel(logrus.DebugLevel)
|
||||
}
|
||||
}
|
||||
|
||||
func configMissing(key string) {
|
||||
logrus.Fatalf("config: %s not set!", key)
|
||||
}
|
||||
|
||||
func configOOB(key string, v int) {
|
||||
logrus.Fatal("config: illegal value %d for %key!", v, key)
|
||||
}
|
||||
|
26
config.yml
26
config.yml
@ -1,6 +1,24 @@
|
||||
server_url: localhost:6969
|
||||
token: abc
|
||||
# OD-Database server settings
|
||||
server:
|
||||
# Connection URL
|
||||
url: localhost:6969
|
||||
# Server auth token
|
||||
token:
|
||||
|
||||
# Log output settings
|
||||
output:
|
||||
# Statistics printing interval
|
||||
stats_interval: 1s
|
||||
verbose: true
|
||||
# More output? (Every listed dir)
|
||||
verbose: false
|
||||
|
||||
# Crawler settings
|
||||
crawl:
|
||||
# Number of sites that can be
|
||||
# processed at once
|
||||
tasks: 3
|
||||
# Number of connections per site
|
||||
connections: 2
|
||||
# How often to retry getting data
|
||||
# from the site before giving up
|
||||
retries: 5
|
||||
workers: 80
|
Loading…
x
Reference in New Issue
Block a user