github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/fgs/v2/dependencies/results.go (about) 1 package dependencies 2 3 import ( 4 "strconv" 5 6 "github.com/huaweicloud/golangsdk/pagination" 7 ) 8 9 // Dependency is an object struct that represents the elements of the dependencies parameter. 10 type Dependency struct { 11 // Dependency ID. 12 ID string `json:"id"` 13 // Dependency owner. 14 Owner string `json:"owner"` 15 // URL of the dependency in the OBS console. 16 Link string `json:"link"` 17 // Runtime. 18 Runtime string `json:"runtime"` 19 // Unique ID of the dependency. 20 Etag string `json:"etag"` 21 // Size of the dependency. 22 Size int `json:"size"` 23 // Name of the dependency. 24 Name string `json:"name"` 25 // Description of the dependency. 26 Description string `json:"description"` 27 // File name of the dependency. 28 FileName string `json:"file_name"` 29 } 30 31 // ListResp is an object struct that represents the result of each page. 32 type ListResp struct { 33 // Next read location. 34 Next int `json:"next_marker"` 35 // Total number of dependencies. 36 Count int `json:"count"` 37 // Dependency list. 38 Dependencies []Dependency `json:"dependencies"` 39 } 40 41 // DependencyPage represents the response pages of the List method. 42 type DependencyPage struct { 43 pagination.MarkerPageBase 44 } 45 46 // IsEmpty returns true if a ListResult no dependent package. 47 func (r DependencyPage) IsEmpty() (bool, error) { 48 resp, err := ExtractDependencies(r) 49 return len(resp.Dependencies) == 0, err 50 } 51 52 // LastMarker returns the last marker index in a ListResult. 53 func (r DependencyPage) LastMarker() (string, error) { 54 resp, err := ExtractDependencies(r) 55 if err != nil { 56 return "", err 57 } 58 if resp.Next >= resp.Count { 59 return "", nil 60 } 61 return strconv.Itoa(resp.Next), nil 62 } 63 64 // NextPageURL generates the URL for the page of results after this one. 65 func (r DependencyPage) NextPageURL() (string, error) { 66 currentURL := r.URL 67 68 mark, err := r.Owner.LastMarker() 69 if err != nil { 70 return "", err 71 } 72 if mark == "" { 73 return "", nil 74 } 75 76 q := currentURL.Query() 77 q.Set("marker", mark) 78 currentURL.RawQuery = q.Encode() 79 80 return currentURL.String(), nil 81 } 82 83 // ExtractDependencies is a method which to extract the response to a dependent package list, next marker index and 84 // count number. 85 func ExtractDependencies(r pagination.Page) (ListResp, error) { 86 var s ListResp 87 err := r.(DependencyPage).Result.ExtractInto(&s) 88 return s, err 89 }