|
- package config
-
- import (
- "fmt"
- "os"
-
- "gopkg.in/yaml.v3"
- )
-
- // Request contains the information to draw a pattern for a specific owner, with corresponding
- // sizes and the template name.
- type Request struct {
- Sizes Sizes `yaml:"sizes,omitempty"`
- Owner string `yaml:"owner"`
- Template string `yaml:"template,omitempty"`
- }
-
- // Sizes defines a map with the size name and the size value.
- type Sizes map[string]float64
-
- // LoadConfig reads and decodes a [Request] from a yaml file.
- func LoadConfig(name string) (Request, error) {
- fh, err := os.Open(name)
- if err != nil {
- return Request{}, fmt.Errorf("open pattern file %q: %w", name, err)
- }
-
- pat := Request{}
-
- err = yaml.NewDecoder(fh).Decode(&pat)
- if err != nil {
- return Request{}, fmt.Errorf("decode content of file %q as yaml: %w", name, err)
- }
-
- return pat, nil
- }
|