-
Notifications
You must be signed in to change notification settings - Fork 0
/
parse.go
62 lines (52 loc) · 1.12 KB
/
parse.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
package main
import "gopkg.in/yaml.v3"
type parse struct {
Packages map[string]struct {
Dependency string
Description interface{}
Source string
Version string
}
}
type LockFile struct {
Packages map[string]Package
}
type PackageDescription struct {
Name string
URL string
}
type Package struct {
Dependency string
Description PackageDescription
Source string
Version string
}
func parseLockFile(lockFileContent []byte) (*LockFile, error) {
internal := parse{}
err := yaml.Unmarshal(lockFileContent, &internal)
if err != nil {
return nil, err
}
l := LockFile{Packages: map[string]Package{}}
for k, v := range internal.Packages {
var descr PackageDescription
if m, ok := v.Description.(map[string]interface{}); ok {
descr = PackageDescription{
Name: m["name"].(string),
URL: m["url"].(string),
}
} else if s, ok := v.Description.(string); ok {
descr = PackageDescription{
Name: s,
URL: "local",
}
}
l.Packages[k] = Package{
Dependency: v.Dependency,
Description: descr,
Source: v.Source,
Version: v.Version,
}
}
return &l, nil
}