nurse/config/decoder.go

44 lines
853 B
Go
Raw Normal View History

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
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
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)
}