wisski-cloud-distillery/internal/config/read.go
Tom Wiesing 945329a080
Move to yaml-based configuration
This commit updates the configuration to be yaml-based and updates the
configuration to read in a yaml file.
2023-02-25 09:14:56 +01:00

32 lines
816 B
Go

package config
import (
"io"
"github.com/FAU-CDI/wisski-distillery/internal/config/validators"
"github.com/FAU-CDI/wisski-distillery/pkg/environment"
"github.com/FAU-CDI/wisski-distillery/pkg/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(env environment.Environment, src io.Reader) error {
// read yaml!
{
decoder := yaml.NewDecoder(src)
decoder.KnownFields(true)
if err := decoder.Decode(config); err != nil {
return err
}
}
// do the validator
return validator.Validate(config, validators.New(env))
}
func (config *Config) Marshal(dest io.Writer) error {
encoder := yaml.NewEncoder(dest)
encoder.SetIndent(4)
return encoder.Encode(config)
}