github.com/coreos/mantle@v0.13.0/kola/torcx/torcx_manifest.go (about) 1 // Copyright 2017 CoreOS, Inc. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package torcx 16 17 import ( 18 "encoding/json" 19 "errors" 20 ) 21 22 const packageListKind = "torcx-package-list-v0" 23 24 type Manifest struct { 25 Packages []Package 26 } 27 28 // a copy of the Manifest type with no UnmarshalJSON method so the below doesn't do a round of recursion 29 type torcxManifestUnmarshalValue struct { 30 Packages []Package 31 } 32 33 func (t *Manifest) UnmarshalJSON(b []byte) error { 34 if t == nil { 35 return errors.New("Unmarshal(nil *Manifest)") 36 } 37 wrappingType := struct { 38 Kind string `json:"kind"` 39 Value torcxManifestUnmarshalValue `json:"value"` 40 }{} 41 42 if err := json.Unmarshal(b, &wrappingType); err != nil { 43 return err 44 } 45 if wrappingType.Kind != packageListKind { 46 return errors.New("Unrecognized torcx packagelist kind: " + wrappingType.Kind) 47 } 48 49 t.Packages = wrappingType.Value.Packages 50 return nil 51 } 52 53 type Package struct { 54 Name string 55 DefaultVersion *string 56 Versions []Version 57 } 58 59 type Version struct { 60 Version string 61 Hash string 62 CasDigest string 63 SourcePackage string 64 Locations []Location 65 } 66 67 type Location struct { 68 Path *string 69 URL *string 70 }