2022-05-08 09:00:22 +00:00
|
|
|
package config
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"io"
|
|
|
|
|
|
|
|
"gopkg.in/yaml.v3"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
_ configDecoder = (*jsonDecoder)(nil)
|
|
|
|
_ configDecoder = (*yamlDecoder)(nil)
|
|
|
|
)
|
|
|
|
|
|
|
|
type configDecoder interface {
|
|
|
|
DecodeConfig(into *Nurse) error
|
|
|
|
}
|
|
|
|
|
2022-06-09 20:40:32 +00:00
|
|
|
//nolint:ireturn // is required to fulfill a common function signature
|
2022-05-08 09:00:22 +00:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
|
2022-06-09 20:40:32 +00:00
|
|
|
//nolint:ireturn // is required to fulfill a common function signature
|
2022-05-08 09:00:22 +00:00
|
|
|
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)
|
|
|
|
}
|