-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.go
More file actions
47 lines (38 loc) · 1.16 KB
/
config.go
File metadata and controls
47 lines (38 loc) · 1.16 KB
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
// Copyright 2017 Sebastian Stauch. All rights reserved.
// Use of this source code is governed by a MIT style
// license that can be found in the LICENSE file.
package main
import (
"io/ioutil"
"github.com/ghodss/yaml"
)
type TlsParams struct {
CertFile string `json:"certFile"`
KeyFile string `json:"keyFile"`
AllowedOrgs []string `json:"allowedOrgs,omitempty"`
}
type Headers map[string]string
type Configuration struct {
CaFiles []string `json:"caFiles,omitempty"`
ListenAddress string `json:"listenAddress"`
MetricsAddress string `json:"metricsAddress"`
VHosts []struct {
TargetAddress string `json:"targetAddress"`
Hostname string `json:"hostname"`
Tls TlsParams `json:"tls"`
Log bool `json:"log"`
Headers Headers `json:"headers,omitempty"`
} `json:"vHosts,inline"`
}
func LoadConfig(configfile string) (Configuration, error) {
configContent, err := ioutil.ReadFile(configfile)
if err != nil {
return Configuration{}, err
}
var config Configuration
err = yaml.Unmarshal(configContent, &config)
if err != nil {
return Configuration{}, err
}
return config, nil
}