generator.go 717 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. package generator
  2. import (
  3. "io/ioutil"
  4. "gogs.carduccidante.edu.it/karmen/core/config"
  5. "gopkg.in/yaml.v2"
  6. )
  7. type Generator interface {
  8. Run()
  9. SetJobId(id uint)
  10. }
  11. type Config struct {
  12. config.ConfigT
  13. KeepArtifacts bool `yaml:"keep_artifacts"`
  14. OutputPath string `yaml:"output_path"`
  15. CloudPath string `yaml:"cloud_path"`
  16. }
  17. var (
  18. Generators map[string]Generator
  19. )
  20. // ReadFile reads the config file placed at the given path.
  21. func ReadFile(path string, conf *Config) error {
  22. err := config.ReadFile(path, &conf.ConfigT)
  23. if err != nil {
  24. return err
  25. }
  26. cf, err := ioutil.ReadFile(path)
  27. if err != nil {
  28. return err
  29. }
  30. if err := yaml.Unmarshal(cf, conf); err != nil {
  31. return err
  32. }
  33. return nil
  34. }