github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/imageservice/v2/images/urls.go (about) 1 package images 2 3 import ( 4 "net/url" 5 "strings" 6 7 "github.com/huaweicloud/golangsdk" 8 "github.com/huaweicloud/golangsdk/openstack/utils" 9 ) 10 11 // `listURL` is a pure function. `listURL(c)` is a URL for which a GET 12 // request will respond with a list of images in the service `c`. 13 func listURL(c *golangsdk.ServiceClient) string { 14 return c.ServiceURL("images") 15 } 16 17 func createURL(c *golangsdk.ServiceClient) string { 18 return c.ServiceURL("images") 19 } 20 21 // `imageURL(c,i)` is the URL for the image identified by ID `i` in 22 // the service `c`. 23 func imageURL(c *golangsdk.ServiceClient, imageID string) string { 24 return c.ServiceURL("images", imageID) 25 } 26 27 // `getURL(c,i)` is a URL for which a GET request will respond with 28 // information about the image identified by ID `i` in the service 29 // `c`. 30 func getURL(c *golangsdk.ServiceClient, imageID string) string { 31 return imageURL(c, imageID) 32 } 33 34 func updateURL(c *golangsdk.ServiceClient, imageID string) string { 35 return imageURL(c, imageID) 36 } 37 38 func deleteURL(c *golangsdk.ServiceClient, imageID string) string { 39 return imageURL(c, imageID) 40 } 41 42 // builds next page full url based on current url 43 func nextPageURL(serviceURL, requestedNext string) (string, error) { 44 base, err := utils.BaseEndpoint(serviceURL) 45 if err != nil { 46 return "", err 47 } 48 49 requestedNextURL, err := url.Parse(requestedNext) 50 if err != nil { 51 return "", err 52 } 53 54 base = golangsdk.NormalizeURL(base) 55 nextPath := base + strings.TrimPrefix(requestedNextURL.Path, "/") 56 57 nextURL, err := url.Parse(nextPath) 58 if err != nil { 59 return "", err 60 } 61 62 nextURL.RawQuery = requestedNextURL.RawQuery 63 64 return nextURL.String(), nil 65 }