forked from TykTechnologies/tyk-pump
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
54 lines (45 loc) · 2.22 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
package main
import (
"encoding/json"
"io/ioutil"
"github.com/kelseyhightower/envconfig"
"github.com/TykTechnologies/tyk-pump/analytics"
"github.com/TykTechnologies/tyk-pump/storage"
)
const ENV_PREVIX = "TYK_PMP"
type PumpConfig struct {
Name string `json:"name"` // Deprecated
Type string `json:"type"`
Filters analytics.AnalyticsFilters `json:"filters"`
Timeout int `json:"timeout"`
OmitDetailedRecording bool `json:"omit_detailed_recording"`
Meta map[string]interface{} `json:"meta"` // TODO: convert this to json.RawMessage and use regular json.Unmarshal
}
type TykPumpConfiguration struct {
PurgeDelay int `json:"purge_delay"`
DontPurgeUptimeData bool `json:"dont_purge_uptime_data"`
UptimePumpConfig map[string]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"`
LogLevel string `json:"log_level"`
HealthCheckEndpointName string `json:"health_check_endpoint_name"`
HealthCheckEndpointPort int `json:"health_check_endpoint_port"`
OmitDetailedRecording bool `json:"omit_detailed_recording"`
}
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)
}
}