/
config.go
58 lines (46 loc) 路 1.36 KB
/
config.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
58
package main
import (
"errors"
"github.com/hashicorp/hcl/v2/hclsimple"
)
// Config top level configuration options
type Config struct {
Formulae []FormulaConfig `hcl:"formula,block"`
}
// FormulaConfig all the required data for the formulae.
type FormulaConfig struct {
Product string `hcl:"product"`
Name string `hcl:"name"`
Desc string `hcl:"desc"`
Homepage string `hcl:"homepage"`
Architectures FormulaArchitectures `hcl:"architectures,block"`
Version string
}
// FormulaArchitectures architecture support
type FormulaArchitectures struct {
Amd64 Architecture `hcl:"amd64,block"`
Aarch64 Architecture `hcl:"aarch64,block"`
}
type Architecture struct {
DarwinFormula FormulaMetadata `hcl:"darwin,block"`
LinuxFormula FormulaMetadata `hcl:"linux,block"`
}
type FormulaMetadata struct {
Enable bool `hcl:"enable"`
Binary string `hcl:"binary,optional"`
ReleaseURL string
ShaSum string
}
func loadConfig(filepath string) (Config, error) {
var config Config
err := hclsimple.DecodeFile(filepath, nil, &config)
return config, err
}
func (c Config) getFormula(product string) (FormulaConfig, error) {
for _, formula := range c.Formulae {
if formula.Product == product {
return formula, nil
}
}
return FormulaConfig{}, errors.New("formula not found")
}