github.com/chnsz/golangsdk@v0.0.0-20240506093406-85a3fbfa605b/openstack/dds/v3/users/results.go (about) 1 package users 2 3 import ( 4 "encoding/json" 5 6 "github.com/chnsz/golangsdk/openstack/dds/v3/roles" 7 "github.com/chnsz/golangsdk/pagination" 8 ) 9 10 // ListResp is the structure that represents the API response of 'List' method. 11 type ListResp struct { 12 // Total number of query results. 13 TotalCount int `json:"total_count"` 14 // List of users to query. 15 Users string `json:"users"` 16 } 17 18 // UserResp is the structure that represents the detail of the database user. 19 type UserResp struct { 20 // Whether role is built-in. 21 IsBuiltin bool `json:"isBuiltin"` 22 // Role name. 23 Name string `json:"user"` 24 // Database name. 25 DbName string `json:"db"` 26 // The list of privileges inherited by the newly created role. 27 Privileges []roles.Privilege `json:"privileges"` 28 // The list of privileges inherited by the newly created role, includes all privileges inherited by inherited roles. 29 InheritedPrivileges []roles.Privilege `json:"inheritedPrivileges"` 30 // The list of roles inherited by the newly created role. 31 Roles []roles.RoleDetail `json:"roles"` 32 // The list of roles inherited by the newly created role, includes all roles inherited by inherited roles. 33 InheritedRoles []roles.RoleDetail `json:"inheritedRoles"` 34 } 35 36 // UserPage is a single page maximum result representing a query by offset page. 37 type UserPage struct { 38 pagination.OffsetPageBase 39 } 40 41 // IsEmpty checks whether a RolePage struct is empty. 42 func (p UserPage) IsEmpty() (bool, error) { 43 arr, err := ExtractUsers(p) 44 return len(arr) == 0, err 45 } 46 47 // ExtractUsers is a method to extract the list of database role for DDS service. 48 func ExtractUsers(p pagination.Page) ([]UserResp, error) { 49 var r ListResp 50 err := (p.(UserPage)).ExtractInto(&r) 51 if err != nil { 52 return nil, err 53 } 54 var ur []UserResp 55 if r.Users != "" { 56 err = json.Unmarshal([]byte(r.Users), &ur) 57 } 58 return ur, err 59 }