This repository has been archived by the owner on Sep 9, 2022. It is now read-only.
forked from TykTechnologies/tyk-pump
-
Notifications
You must be signed in to change notification settings - Fork 1
/
config.go
45 lines (36 loc) · 1.45 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
package main
import (
"encoding/json"
"io/ioutil"
"github.com/TykTechnologies/tyk-pump/storage"
"github.com/kelseyhightower/envconfig"
)
const ENV_PREVIX string = "TYK_PMP"
type PumpConfig struct {
Name string `json:"name"`
Meta map[string]interface{} `json:"meta"`
}
type TykPumpConfiguration struct {
PurgeDelay int `json:"purge_delay"`
DontPurgeUptimeData bool `json:"dont_purge_uptime_data"`
UptimePumpConfig interface{} `json:"uptime_pump_config"`
Pumps map[string]PumpConfig `json:"pumps"`
AnalyticsStorageType string `json:"analytics_storage_type"`
AnalyticsStorageConfig storage.RedisStorageConfig `json:"analytics_storage_config"`
StatsdConnectionString string `json:"statsd_connection_string"`
StatsdPrefix string `json:"statsd_prefix"`
}
func LoadConfig(filePath *string, configStruct *TykPumpConfiguration) {
configuration, err := ioutil.ReadFile(*filePath)
if err != nil {
log.Fatal("Couldn't load configuration file: ", err)
}
marshalErr := json.Unmarshal(configuration, &configStruct)
if marshalErr != nil {
log.Fatal("Couldn't unmarshal configuration: ", marshalErr)
}
overrideErr := envconfig.Process(ENV_PREVIX, configStruct)
if overrideErr != nil {
log.Error("Failed to process environment variables after file load: ", overrideErr)
}
}