shoebill/internal/config/config.go
2023-08-01 13:01:40 +02:00

32 lines
793 B
Go

package config
import (
"os"
"git.badhouseplants.net/allanger/giops/internal/config/cluster"
"git.badhouseplants.net/allanger/giops/internal/config/release"
"git.badhouseplants.net/allanger/giops/internal/config/repository"
"github.com/sirupsen/logrus"
"gopkg.in/yaml.v2"
)
type Config struct {
Repositories repository.Repositories
Releases release.Releases
Clusters cluster.Clusters
}
// NewConfigFromFile populates the config struct from a configuration yaml file
func NewConfigFromFile(path string) (*Config, error) {
var config Config
logrus.Infof("reading the config file: %s", path)
configFile, err := os.ReadFile(path)
if err != nil {
return nil, err
}
if err := yaml.Unmarshal(configFile, &config); err != nil {
return nil, err
}
return &config, nil
}