...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package v1
16
17 import (
18 "encoding/json"
19 "io"
20
21 "github.com/google/go-containerregistry/pkg/v1/types"
22 )
23
24
25 type Manifest struct {
26 SchemaVersion int64 `json:"schemaVersion"`
27 MediaType types.MediaType `json:"mediaType,omitempty"`
28 Config Descriptor `json:"config"`
29 Layers []Descriptor `json:"layers"`
30 Annotations map[string]string `json:"annotations,omitempty"`
31 Subject *Descriptor `json:"subject,omitempty"`
32 }
33
34
35 type IndexManifest struct {
36 SchemaVersion int64 `json:"schemaVersion"`
37 MediaType types.MediaType `json:"mediaType,omitempty"`
38 Manifests []Descriptor `json:"manifests"`
39 Annotations map[string]string `json:"annotations,omitempty"`
40 Subject *Descriptor `json:"subject,omitempty"`
41 }
42
43
44 type Descriptor struct {
45 MediaType types.MediaType `json:"mediaType"`
46 Size int64 `json:"size"`
47 Digest Hash `json:"digest"`
48 Data []byte `json:"data,omitempty"`
49 URLs []string `json:"urls,omitempty"`
50 Annotations map[string]string `json:"annotations,omitempty"`
51 Platform *Platform `json:"platform,omitempty"`
52 ArtifactType string `json:"artifactType,omitempty"`
53 }
54
55
56 func ParseManifest(r io.Reader) (*Manifest, error) {
57 m := Manifest{}
58 if err := json.NewDecoder(r).Decode(&m); err != nil {
59 return nil, err
60 }
61 return &m, nil
62 }
63
64
65 func ParseIndexManifest(r io.Reader) (*IndexManifest, error) {
66 im := IndexManifest{}
67 if err := json.NewDecoder(r).Decode(&im); err != nil {
68 return nil, err
69 }
70 return &im, nil
71 }
72
View as plain text