This repository has been archived by the owner on Jul 16, 2019. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
proxyConfig.go
58 lines (47 loc) · 1.54 KB
/
proxyConfig.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
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"gopkg.in/yaml.v2"
)
type proxyConfig struct {
Domains map[string]domainConfig `json:"domains" yaml:"domains"`
Generic string `json:"generic" yaml:"generic"`
Docker dockerConfig `json:"docker" yaml:"docker"`
ListenHTTP string `json:"listenHTTP" yaml:"listenHTTP"`
ListenHTTPS string `json:"listenHTTPS" yaml:"listenHTTPS"`
}
type domainConfig struct {
SSL sslConfig `json:"ssl,omitempty" yaml:"ssl,omitempty"`
Slug string `json:"slug" yaml:"slug"`
ForceSSL bool `json:"force_ssl" yaml:"force_ssl"`
Authentication domainAuth `json:"authentication,omitempty" yaml:"authentication,omitempty"`
}
type domainAuth struct {
Type string `json:"type" yaml:"type"`
Config interface{} `json:"config" yaml:"config"`
}
type sslConfig struct {
Cert string `json:"cert" yaml:"cert"`
Key string `json:"key" yaml:"key"`
}
type dockerConfig struct {
Hosts map[string]string `json:"hosts" yaml:"hosts"`
Port int `json:"port" yaml:"port"`
}
func newProxyConfig(configFile string) (*proxyConfig, error) {
tmp := proxyConfig{}
configBody, err := ioutil.ReadFile(configFile)
if err != nil {
return nil, fmt.Errorf("Unable to load config file: %s", err)
}
err = yaml.Unmarshal(configBody, &tmp)
if err != nil {
err := json.Unmarshal(configBody, &tmp)
if err != nil {
return nil, fmt.Errorf("Failed to read yaml & json from config file")
}
}
return &tmp, nil
}