Peter Kurfer
4c2aa968d2
- support config file - support reading checks, server definition and endpoint definitions from env
41 lines
711 B
Go
41 lines
711 B
Go
package config
|
|
|
|
import (
|
|
"encoding/json"
|
|
"io"
|
|
|
|
"gopkg.in/yaml.v3"
|
|
)
|
|
|
|
var (
|
|
_ configDecoder = (*jsonDecoder)(nil)
|
|
_ configDecoder = (*yamlDecoder)(nil)
|
|
)
|
|
|
|
type configDecoder interface {
|
|
DecodeConfig(into *Nurse) error
|
|
}
|
|
|
|
func newJSONDecoder(r io.Reader) configDecoder {
|
|
return &jsonDecoder{decoder: json.NewDecoder(r)}
|
|
}
|
|
|
|
type jsonDecoder struct {
|
|
decoder *json.Decoder
|
|
}
|
|
|
|
func (j jsonDecoder) DecodeConfig(into *Nurse) error {
|
|
return j.decoder.Decode(into)
|
|
}
|
|
|
|
func newYAMLDecoder(r io.Reader) configDecoder {
|
|
return &yamlDecoder{decoder: yaml.NewDecoder(r)}
|
|
}
|
|
|
|
type yamlDecoder struct {
|
|
decoder *yaml.Decoder
|
|
}
|
|
|
|
func (y yamlDecoder) DecodeConfig(into *Nurse) error {
|
|
return y.decoder.Decode(into)
|
|
}
|