wisski-cloud-distillery/internal/config/read.go
Tom Wiesing 473040a69f
Remove environment.Environment struct
This commit completely removes the environment struct as it is no longer
used.
2023-03-02 12:52:51 +01:00

36 lines
879 B
Go

package config
import (
"io"
"github.com/FAU-CDI/wisski-distillery/internal/config/validators"
"github.com/tkw1536/pkglib/validator"
"gopkg.in/yaml.v3"
)
// Unmarshal reads configuration from the provided io.Reader, and then validates it.
// Configuration is read in yaml format.
func (config *Config) Unmarshal(src io.Reader) error {
// read yaml!
{
decoder := yaml.NewDecoder(src)
decoder.KnownFields(true)
if err := decoder.Decode(config); err != nil {
return err
}
}
// TODO: should this be done seperatly?
return config.Validate()
}
// Validate validates this configuration file and sets appropriate defaults
func (config *Config) Validate() error {
return validator.Validate(config, validators.New())
}
func (config *Config) Marshal(dest io.Writer) error {
encoder := yaml.NewEncoder(dest)
encoder.SetIndent(4)
return encoder.Encode(config)
}