Created
June 8, 2020 09:41
-
-
Save rueian/6142b6cc0b2e51ffed476172ff6aa652 to your computer and use it in GitHub Desktop.
envoy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package main | |
| import ( | |
| "fmt" | |
| "io/ioutil" | |
| "os" | |
| "gopkg.in/yaml.v2" | |
| ) | |
| type Config struct { | |
| Services []Service `yaml:"services"` | |
| Hosts []Host `yaml:"hosts"` | |
| } | |
| type Service struct { | |
| Name string `yaml:"name"` | |
| Address string `yaml:"address"` | |
| Type string `yaml:"type"` | |
| } | |
| type RetryPolicy struct { | |
| RetryOn string `yaml:"retryOn"` // https://www.envoyproxy.io/docs/envoy/latest/configuration/http_filters/router_filter#id4 | |
| NumRetries uint32 `yaml:"numRetries"` | |
| } | |
| type Host struct { | |
| Name string `yaml:"name"` | |
| Domains []string `yaml:"domains"` | |
| Routes []Route `yaml:"routes"` | |
| AddRequestHeaders []Header `yaml:"addRequestHeaders"` | |
| AddResponseHeaders []Header `yaml:"addResponseHeaders"` | |
| RemoveResponseHeaders []string `yaml:"removeResponseHeaders"` | |
| RetryPolicy RetryPolicy `yaml:"retryPolicy"` | |
| } | |
| type Route struct { | |
| Path string `yaml:"path"` | |
| Prefix string `yaml:"prefix"` | |
| Match string `yaml:"match"` | |
| Service string `yaml:"service"` | |
| AddRequestHeaders []Header `yaml:"addRequestHeaders"` | |
| AddResponseHeaders []Header `yaml:"addResponseHeaders"` | |
| RemoveResponseHeaders []string `yaml:"removeResponseHeaders"` | |
| PrefixRewrite string `yaml:"prefixRewrite"` | |
| HostRewrite string `yaml:"hostRewrite"` | |
| AutoHostRewrite bool `yaml:"autoHostRewrite"` | |
| RetryPolicy RetryPolicy `yaml:"retryPolicy"` | |
| } | |
| type Header struct { | |
| Name string `yaml:"name"` | |
| Value string `yaml:"value"` | |
| } | |
| func main() { | |
| data, err := ioutil.ReadFile(os.Getenv("CONFIG_PATH")) | |
| if err != nil { | |
| panic(err) | |
| } | |
| var config Config | |
| if err := yaml.UnmarshalStrict([]byte(os.ExpandEnv(string(data))), &config); err != nil { | |
| panic(err) | |
| } | |
| fmt.Println(len(config.Services)) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment