-
Notifications
You must be signed in to change notification settings - Fork 2
/
config.go
60 lines (49 loc) · 1.58 KB
/
config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// -*- Go -*-
/* ------------------------------------------------ */
/* Golang source */
/* Author: Alexei Panov <[email protected]> */
/* ------------------------------------------------ */
package main
import (
"time"
log "github.com/sirupsen/logrus"
"github.com/spf13/viper"
)
// Options is a type for store all application options
type Options struct {
APIKey string
PgSQLDSN string
LogLevel string
ServerAddr string
Debug bool
StaticDirPath string
MaximumFloodLevel int
CacheDuration time.Duration
CacheUpdatePeriod time.Duration
FeedsUpdatePeriod time.Duration
}
var options *Options
// LoadConfig function loads configuration file and set options
func LoadConfig() (err error) {
log.Warnf("Load configuration file...")
viper.SetConfigName(configName)
viper.AddConfigPath(".")
viper.AddConfigPath("/etc")
viper.AddConfigPath("/usr/local/etc")
if err = viper.ReadInConfig(); err != nil {
return
}
options = &Options{
APIKey: viper.GetString("main.api_key"),
PgSQLDSN: viper.GetString("pgsql.dsn"),
LogLevel: viper.GetString("log.level"),
ServerAddr: viper.GetString("http.addr"),
Debug: viper.GetBool("main.debug"),
StaticDirPath: viper.GetString("main.static_path"),
MaximumFloodLevel: viper.GetInt("main.maximum_flood_level"),
CacheDuration: viper.GetDuration("cache.duration"),
CacheUpdatePeriod: viper.GetDuration("cache.update_period"),
FeedsUpdatePeriod: viper.GetDuration("feeds.update_period"),
}
return
}