-
Notifications
You must be signed in to change notification settings - Fork 14
/
cfg.go
57 lines (50 loc) · 1 KB
/
cfg.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
54
55
56
57
package main
import (
"archive/zip"
"bytes"
_ "embed"
"os"
"github.com/pkg/errors"
"gopkg.in/yaml.v3"
)
type config struct {
BaseURL string `yaml:"BaseURL"`
Targets []targets `yaml:"Targets"`
}
type targets struct {
Refer string `yaml:"Refer"`
Folder string `yaml:"Folder"`
Copy []string `yaml:"Copy"`
OS string `yaml:"OS"`
Arch string `yaml:"Arch"`
}
//go:embed cfg.zip
var cfgdata []byte
var cfg = func() *zip.Reader {
r, err := zip.NewReader(bytes.NewReader(cfgdata), int64(len(cfgdata)))
if err != nil {
panic(err)
}
for _, f := range r.File {
cmdlst = append(cmdlst, f.Name)
}
return r
}()
func readconfig(path string, usecust bool) (c config, err error) {
fname := path + ".yaml"
f, err := cfg.Open(fname)
if usecust && err != nil {
f, err = os.Open(fname)
}
if err != nil {
err = errors.Wrap(err, "invalid path")
return
}
defer f.Close()
err = yaml.NewDecoder(f).Decode(&c)
if err != nil {
err = errors.Wrap(err, "invalid config")
return
}
return
}