LoadTLSConfig parses the given file into a tls.Config.
(filename string)
| 31 | |
| 32 | // LoadTLSConfig parses the given file into a tls.Config. |
| 33 | func LoadTLSConfig(filename string) (*tls.Config, error) { |
| 34 | content, err := os.ReadFile(filename) |
| 35 | if err != nil { |
| 36 | return nil, err |
| 37 | } |
| 38 | cfg := TLSConfig{} |
| 39 | switch filepath.Ext(filename) { |
| 40 | case ".yml": |
| 41 | if err = yaml.UnmarshalStrict(content, &cfg); err != nil { |
| 42 | return nil, err |
| 43 | } |
| 44 | case ".json": |
| 45 | decoder := json.NewDecoder(bytes.NewReader(content)) |
| 46 | decoder.DisallowUnknownFields() |
| 47 | if err = decoder.Decode(&cfg); err != nil { |
| 48 | return nil, err |
| 49 | } |
| 50 | default: |
| 51 | return nil, fmt.Errorf("Unknown extension: %s", filepath.Ext(filename)) |
| 52 | } |
| 53 | return NewTLSConfig(&cfg) |
| 54 | } |
| 55 | |
| 56 | var expectedTLSConfigs = []struct { |
| 57 | filename string |
no test coverage detected
searching dependent graphs…