github.com/chnsz/golangsdk@v0.0.0-20240506093406-85a3fbfa605b/openstack/identity/v3/projects/results.go (about) 1 package projects 2 3 import ( 4 "github.com/chnsz/golangsdk" 5 "github.com/chnsz/golangsdk/pagination" 6 ) 7 8 type projectResult struct { 9 golangsdk.Result 10 } 11 12 // GetResult is the result of a Get request. Call its Extract method to 13 // interpret it as a Project. 14 type GetResult struct { 15 projectResult 16 } 17 18 // CreateResult is the result of a Create request. Call its Extract method to 19 // interpret it as a Project. 20 type CreateResult struct { 21 projectResult 22 } 23 24 // DeleteResult is the result of a Delete request. Call its ExtractErr method to 25 // determine if the request succeeded or failed. 26 type DeleteResult struct { 27 golangsdk.ErrResult 28 } 29 30 // UpdateResult is the result of an Update request. Call its Extract method to 31 // interpret it as a Project. 32 type UpdateResult struct { 33 projectResult 34 } 35 36 // Project represents an OpenStack Identity Project. 37 type Project struct { 38 // IsDomain indicates whether the project is a domain. 39 IsDomain bool `json:"is_domain"` 40 41 // Description is the description of the project. 42 Description string `json:"description"` 43 44 // DomainID is the domain ID the project belongs to. 45 DomainID string `json:"domain_id"` 46 47 // Enabled is whether or not the project is enabled. 48 Enabled bool `json:"enabled"` 49 50 // ID is the unique ID of the project. 51 ID string `json:"id"` 52 53 // Name is the name of the project. 54 Name string `json:"name"` 55 56 // ParentID is the parent_id of the project. 57 ParentID string `json:"parent_id"` 58 59 // Status is the status of the project. 60 Status string `json:"status"` 61 } 62 63 // ProjectPage is a single page of Project results. 64 type ProjectPage struct { 65 pagination.LinkedPageBase 66 } 67 68 // IsEmpty determines whether or not a page of Projects contains any results. 69 func (r ProjectPage) IsEmpty() (bool, error) { 70 projects, err := ExtractProjects(r) 71 return len(projects) == 0, err 72 } 73 74 // NextPageURL extracts the "next" link from the links section of the result. 75 func (r ProjectPage) NextPageURL() (string, error) { 76 var s struct { 77 Links struct { 78 Next string `json:"next"` 79 Previous string `json:"previous"` 80 } `json:"links"` 81 } 82 err := r.ExtractInto(&s) 83 if err != nil { 84 return "", err 85 } 86 return s.Links.Next, err 87 } 88 89 // ExtractProjects returns a slice of Projects contained in a single page of 90 // results. 91 func ExtractProjects(r pagination.Page) ([]Project, error) { 92 var s struct { 93 Projects []Project `json:"projects"` 94 } 95 err := (r.(ProjectPage)).ExtractInto(&s) 96 return s.Projects, err 97 } 98 99 // Extract interprets any projectResults as a Project. 100 func (r projectResult) Extract() (*Project, error) { 101 var s struct { 102 Project *Project `json:"project"` 103 } 104 err := r.ExtractInto(&s) 105 return s.Project, err 106 } 107 108 type UpdateStatusResult struct { 109 golangsdk.ErrResult 110 }