-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathload.go
69 lines (57 loc) · 1.12 KB
/
load.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
59
60
61
62
63
64
65
66
67
68
69
package getdoc
import (
"embed"
"encoding/json"
"fmt"
"path"
"github.com/go-faster/errors"
)
// Probably everything below should be code-generated from _schema folder.
// Layers is list of supported layers.
var Layers = []int{
121,
133,
138,
139,
144,
145,
155,
158,
164,
167,
170,
181,
185,
192,
195,
}
// LayerLatest is id of the latest layer.
const LayerLatest = 195
// LayerExists returns true if layer is included in package.
func LayerExists(layer int) bool {
for _, v := range Layers {
if v == layer {
return true
}
}
return false
}
// ErrNotFound means that current package version does not support requested layer.
var ErrNotFound = errors.New("layer not found")
//go:embed _schema
var embedData embed.FS
// Load layer documentation.
func Load(layer int) (*Doc, error) {
if !LayerExists(layer) {
return nil, ErrNotFound
}
b, err := embedData.ReadFile(path.Join("_schema", fmt.Sprintf("%d.json", layer)))
if err != nil {
return nil, errors.Wrap(err, "read")
}
var doc Doc
if err := json.Unmarshal(b, &doc); err != nil {
return nil, errors.Wrap(err, "parse")
}
return &doc, nil
}