-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
64 lines (58 loc) · 1.38 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
61
62
63
64
package geo
import (
"fmt"
log "github.com/sirupsen/logrus"
"github.com/spf13/viper"
"time"
)
const (
_GEO = "geoip"
DATA_DIR = "data/geoip"
DB_NAME = "GeoLite2-City.mmdb"
EDITION = "GeoLite2-City"
DBREFRESH = "24h"
VERBOSE_UPDATE = false
LICENSE_KEY = "testing"
ACCOUNT_ID = 123
)
type GeoIpConfig struct {
AccountId int
DatabaseDirectory string
DatabaseName string
EditionIDs []string
LicenseKey string
RefreshDuration time.Duration
VerboseUpdate bool
}
func InitGeoIpConfig() (config *GeoIpConfig, err error) {
dbrt, _ := time.ParseDuration(DBREFRESH)
config = &GeoIpConfig{
AccountId: ACCOUNT_ID,
DatabaseDirectory: DATA_DIR,
DatabaseName: DB_NAME,
EditionIDs: []string{EDITION},
LicenseKey: LICENSE_KEY,
RefreshDuration: dbrt,
VerboseUpdate: VERBOSE_UPDATE,
}
h := viper.Sub(_GEO)
if h != nil {
err := h.Unmarshal(config)
if err != nil {
log.Error("Geo Config Error: ", err.Error())
return nil, err
}
}
return config, nil
}
func String() string {
return `
[geoip]
RefreshDuration = "` + DBREFRESH + `"
accountId = ` + fmt.Sprintf("%d", ACCOUNT_ID) + `
DatabaseDirectory = "` + DATA_DIR + `"
DatabaseName = "` + DB_NAME + `"
LicenseKey = "` + LICENSE_KEY + `"
Verbose = ` + fmt.Sprintf("%t", VERBOSE_UPDATE) + `
`
}