-
Notifications
You must be signed in to change notification settings - Fork 0
/
shigoto.go
53 lines (43 loc) · 1.01 KB
/
shigoto.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package shigoto
import (
"path/filepath"
"reflect"
"github.com/knadh/koanf"
"github.com/knadh/koanf/parsers/yaml"
"github.com/knadh/koanf/providers/file"
)
const (
globalvariables = "variables"
globalenv = "environment"
entrypoint = "shigoto"
)
// Shigoto represents a shigoto.yml
type Shigoto struct {
Name string
Baito map[string]Baito
konf *koanf.Koanf
}
// Load loads a Shigoto from the given filename.
func Load(filename string) (*Shigoto, error) {
konf := koanf.New(".")
if err := konf.Load(file.Provider(filename), yaml.Parser()); err != nil {
return nil, err
}
shigoto := &Shigoto{
Name: filepath.Base(filename),
Baito: map[string]Baito{},
konf: konf,
}
for _, name := range konf.MapKeys(entrypoint) {
b, err := loadBaito(konf, name)
if err != nil {
return nil, err
}
shigoto.Baito[name] = *b
}
return shigoto, nil
}
// Same returns true if both shigoto are the same.
func (s *Shigoto) Same(shigoto *Shigoto) bool {
return reflect.DeepEqual(s.konf, shigoto.konf)
}