github.com/jghiloni/cli@v6.28.1-0.20170628223758-0ce05fe032a2+incompatible/api/cloudcontroller/ccv2/resource.go (about) 1 package ccv2 2 3 import ( 4 "bytes" 5 "encoding/json" 6 "os" 7 "strconv" 8 9 "code.cloudfoundry.org/cli/api/cloudcontroller" 10 "code.cloudfoundry.org/cli/api/cloudcontroller/ccv2/internal" 11 ) 12 13 type Resource struct { 14 Filename string `json:"fn"` 15 Size int64 `json:"size"` 16 SHA1 string `json:"sha1"` 17 Mode os.FileMode `json:"mode"` 18 } 19 20 func (r Resource) MarshalJSON() ([]byte, error) { 21 var ccResource struct { 22 Filename string `json:"fn,omitempty"` 23 Size int64 `json:"size"` 24 SHA1 string `json:"sha1"` 25 Mode string `json:"mode,omitempty"` 26 } 27 28 ccResource.Filename = r.Filename 29 ccResource.Size = r.Size 30 ccResource.SHA1 = r.SHA1 31 ccResource.Mode = strconv.FormatUint(uint64(r.Mode), 8) 32 return json.Marshal(ccResource) 33 } 34 35 func (client *Client) ResourceMatch(resourcesToMatch []Resource) ([]Resource, Warnings, error) { 36 body, err := json.Marshal(resourcesToMatch) 37 if err != nil { 38 return nil, nil, err 39 } 40 41 request, err := client.newHTTPRequest(requestOptions{ 42 RequestName: internal.PutResourceMatch, 43 Body: bytes.NewReader(body), 44 }) 45 if err != nil { 46 return nil, nil, err 47 } 48 49 var matchedResources []Resource 50 response := cloudcontroller.Response{ 51 Result: &matchedResources, 52 } 53 54 err = client.connection.Make(request, &response) 55 return matchedResources, response.Warnings, err 56 }