-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.go
55 lines (46 loc) · 1.01 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
package main
import (
"io/ioutil"
"log"
"os"
"gopkg.in/yaml.v3"
)
var (
// Version is the semantic version according to the release.
Version string
)
// Config is the ratproxy.yaml.
type Config struct {
Listen string `yaml:"listen"`
UseTLS bool `yaml:"useTLS"`
Targets []*Target `yaml:"targets"`
}
const (
TargetTypeLambda string = "lambda"
TargetTypeEmpty string = ""
)
// Target is a proxy target based on a path.
type Target struct {
Name string `yaml:"name"`
Target string `yaml:"target"`
Path string `yaml:"path"`
Type string `yaml:"type"`
}
// NewConfig reads the yaml configuration file.
func NewConfig() (*Config, error) {
configFilename := os.Getenv("RATPROXY_FILENAME")
if configFilename == "" {
configFilename = "ratproxy.yaml"
}
log.Printf("ratproxy: reading config at %v\n", configFilename)
data, err := ioutil.ReadFile(configFilename)
if err != nil {
return nil, err
}
c := &Config{}
err = yaml.Unmarshal(data, &c)
if err != nil {
return nil, err
}
return c, nil
}