github.com/chnsz/golangsdk@v0.0.0-20240506093406-85a3fbfa605b/openstack/identity/federatedauth/mappings/results.go (about) 1 package mappings 2 3 import ( 4 "github.com/chnsz/golangsdk/pagination" 5 ) 6 7 type IdentityMapping struct { 8 ID string `json:"id"` 9 Rules []MappingRule `json:"rules"` 10 Links LinksSelf `json:"links"` 11 } 12 13 type LinksSelf struct { 14 Self string `json:"self"` 15 } 16 17 type Links struct { 18 Next string `json:"next"` 19 Self string `json:"self"` 20 Previous string `json:"previous"` 21 } 22 23 type IdentityMappingPage struct { 24 pagination.LinkedPageBase 25 } 26 27 func (r IdentityMappingPage) IsEmpty() (bool, error) { 28 mappings, err := ExtractMappings(r) 29 return len(mappings) == 0, err 30 } 31 32 func (r IdentityMappingPage) NextPageURL() (string, error) { 33 var s struct { 34 Links Links `json:"links"` 35 } 36 err := r.ExtractInto(&s) 37 if err != nil { 38 return "", err 39 } 40 url := s.Links.Next 41 if url == "" { 42 return "", nil 43 } 44 return url, nil 45 } 46 47 func ExtractMappings(r pagination.Page) ([]IdentityMapping, error) { 48 var s struct { 49 Links Links `json:"links"` 50 Mappings []IdentityMapping `json:"mappings"` 51 } 52 err := (r.(IdentityMappingPage)).ExtractInto(&s) 53 return s.Mappings, err 54 }