github.com/chnsz/golangsdk@v0.0.0-20240506093406-85a3fbfa605b/openstack/fgs/v2/application/results.go (about) 1 package application 2 3 import ( 4 "strconv" 5 6 "github.com/chnsz/golangsdk/pagination" 7 ) 8 9 // Template is the structure that represents the aplication template details. 10 type Template struct { 11 // Template ID. 12 ID string `json:"id"` 13 // The name of template. 14 Name string `json:"name"` 15 // Template execution runtime. 16 Runtime string `json:"runtime"` 17 // The category of template. 18 Category string `json:"category"` 19 // Template image file(Base64-encoded). 20 Image string `json:"image"` 21 // Template description. 22 Description string `json:"description"` 23 // The type of the function application. 24 Type string `json:"type"` 25 } 26 27 // pageInfo is the structure that represents response of the ListTemplate method. 28 type pageInfo struct { 29 // The list of templates. 30 Templates []Template `json:"templates"` 31 // Next record location. 32 NextMarker int `json:"next_marker"` 33 // Total number of application template. 34 Count int `json:"count"` 35 } 36 37 // TemplatePage represents the response pages of the ListTemplate method. 38 type TemplatePage struct { 39 pagination.MarkerPageBase 40 } 41 42 // IsEmpty returns true if a ListResult no application template. 43 func (r TemplatePage) IsEmpty() (bool, error) { 44 resp, err := extractPageInfo(r) 45 return resp.Count == 0, err 46 } 47 48 // LastMarker returns the last marker index in a pageInfo. 49 func (r TemplatePage) LastMarker() (string, error) { 50 resp, err := extractPageInfo(r) 51 if err != nil { 52 return "", err 53 } 54 if resp.Count == 0 { 55 return "", nil 56 } 57 return strconv.Itoa(resp.NextMarker), nil 58 } 59 60 // NextPageURL generates the URL for the page of results after this one. 61 func (r TemplatePage) NextPageURL() (string, error) { 62 currentURL := r.URL 63 mark, err := r.Owner.LastMarker() 64 if err != nil { 65 return "", err 66 } 67 if mark == "" { 68 return "", nil 69 } 70 71 q := currentURL.Query() 72 q.Set("marker", mark) 73 currentURL.RawQuery = q.Encode() 74 75 return currentURL.String(), nil 76 } 77 78 // extractPageInfo is a method which to extract the response of the page information. 79 func extractPageInfo(r pagination.Page) (*pageInfo, error) { 80 var s pageInfo 81 err := r.(TemplatePage).Result.ExtractInto(&s) 82 return &s, err 83 }