github.com/chnsz/golangsdk@v0.0.0-20240506093406-85a3fbfa605b/openstack/fgs/v2/dependencies/results.go (about) 1 package dependencies 2 3 import ( 4 "strconv" 5 6 "github.com/chnsz/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 } 90 91 // DependencyVersion is an object struct that represents the dependency (with version info) detail. 92 type DependencyVersion struct { 93 // Dependency ID. 94 ID string `json:"id"` 95 // Dependency owner. 96 Owner string `json:"owner"` 97 // URL of the dependency in the OBS console. 98 Link string `json:"link"` 99 // Runtime. 100 Runtime string `json:"runtime"` 101 // Unique ID of the dependency. 102 Etag string `json:"etag"` 103 // Size of the dependency. 104 Size int `json:"size"` 105 // Name of the dependency. 106 Name string `json:"name"` 107 // Description of the dependency. 108 Description string `json:"description"` 109 // File name of the dependency. 110 FileName string `json:"file_name"` 111 // Version of the dependency. 112 Version int `json:"version"` 113 // The ID of the dependency. 114 DepId string `json:"dep_id"` 115 // The last modified time. 116 LastModified int `json:"last_modified"` 117 } 118 119 type DependencyVersionPage struct { 120 pagination.SinglePageBase 121 } 122 123 func extractDependencieVersions(r pagination.Page) ([]DependencyVersion, error) { 124 var s []DependencyVersion 125 err := r.(DependencyVersionPage).Result.ExtractIntoSlicePtr(&s, "dependencies") 126 return s, err 127 }