Debian Codegraph @

org.go

raw symbols SCIP
1 /*
2 * Copyright 2014 VMware, Inc. All rights reserved. Licensed under the Apache v2 License.
3 */
4
5 package govcd
6
7 import (
8 "fmt"
9 "net/url"
10
11 types "github.com/hmrc/vmware-govcd/types/v56"
12 )
13
14 type Org struct {
15 Org *types.Org
16 c *Client
17 }
18
19 func NewOrg(c *Client) *Org {
20 return &Org{
21 Org: new(types.Org),
22 c: c,
23 }
24 }
25
26 func (o *Org) FindCatalog(catalog string) (Catalog, error) {
27
28 for _, av := range o.Org.Link {
29 if av.Rel == "down" && av.Type == "application/vnd.vmware.vcloud.catalog+xml" && av.Name == catalog {
30 u, err := url.ParseRequestURI(av.HREF)
31
32 if err != nil {
33 return Catalog{}, fmt.Errorf("error decoding org response: %s", err)
34 }
35
36 req := o.c.NewRequest(map[string]string{}, "GET", *u, nil)
37
38 resp, err := checkResp(o.c.Http.Do(req))
39 if err != nil {
40 return Catalog{}, fmt.Errorf("error retreiving catalog: %s", err)
41 }
42
43 cat := NewCatalog(o.c)
44
45 if err = decodeBody(resp, cat.Catalog); err != nil {
46 return Catalog{}, fmt.Errorf("error decoding catalog response: %s", err)
47 }
48
49 // The request was successful
50 return *cat, nil
51
52 }
53 }
54
55 return Catalog{}, fmt.Errorf("can't find catalog: %s", catalog)
56 }