您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

37 行
835B

  1. package config
  2. import (
  3. "fmt"
  4. "os"
  5. "gopkg.in/yaml.v3"
  6. )
  7. // Request contains the information to draw a pattern for a specific owner, with corresponding
  8. // sizes and the template name.
  9. type Request struct {
  10. Sizes Sizes `yaml:"sizes,omitempty"`
  11. Owner string `yaml:"owner"`
  12. Template string `yaml:"template,omitempty"`
  13. }
  14. // Sizes defines a map with the size name and the size value.
  15. type Sizes map[string]float64
  16. // LoadConfig reads and decodes a [Request] from a yaml file.
  17. func LoadConfig(name string) (Request, error) {
  18. fh, err := os.Open(name)
  19. if err != nil {
  20. return Request{}, fmt.Errorf("open pattern file %q: %w", name, err)
  21. }
  22. pat := Request{}
  23. err = yaml.NewDecoder(fh).Decode(&pat)
  24. if err != nil {
  25. return Request{}, fmt.Errorf("decode content of file %q as yaml: %w", name, err)
  26. }
  27. return pat, nil
  28. }