github.com/gophercloud/gophercloud@v1.11.0/openstack/db/v1/users/results.go (about)

     1  package users
     2  
     3  import (
     4  	"github.com/gophercloud/gophercloud"
     5  	db "github.com/gophercloud/gophercloud/openstack/db/v1/databases"
     6  	"github.com/gophercloud/gophercloud/pagination"
     7  )
     8  
     9  // User represents a database user
    10  type User struct {
    11  	// The user name
    12  	Name string
    13  
    14  	// The user password
    15  	Password string
    16  
    17  	// The databases associated with this user
    18  	Databases []db.Database
    19  }
    20  
    21  // CreateResult represents the result of a create operation.
    22  type CreateResult struct {
    23  	gophercloud.ErrResult
    24  }
    25  
    26  // DeleteResult represents the result of a delete operation.
    27  type DeleteResult struct {
    28  	gophercloud.ErrResult
    29  }
    30  
    31  // UserPage represents a single page of a paginated user collection.
    32  type UserPage struct {
    33  	pagination.LinkedPageBase
    34  }
    35  
    36  // IsEmpty checks to see whether the collection is empty.
    37  func (page UserPage) IsEmpty() (bool, error) {
    38  	if page.StatusCode == 204 {
    39  		return true, nil
    40  	}
    41  
    42  	users, err := ExtractUsers(page)
    43  	return len(users) == 0, err
    44  }
    45  
    46  // NextPageURL will retrieve the next page URL.
    47  func (page UserPage) NextPageURL() (string, error) {
    48  	var s struct {
    49  		Links []gophercloud.Link `json:"users_links"`
    50  	}
    51  	err := page.ExtractInto(&s)
    52  	if err != nil {
    53  		return "", err
    54  	}
    55  	return gophercloud.ExtractNextURL(s.Links)
    56  }
    57  
    58  // ExtractUsers will convert a generic pagination struct into a more
    59  // relevant slice of User structs.
    60  func ExtractUsers(r pagination.Page) ([]User, error) {
    61  	var s struct {
    62  		Users []User `json:"users"`
    63  	}
    64  	err := (r.(UserPage)).ExtractInto(&s)
    65  	return s.Users, err
    66  }