github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/imageservice/v2/tasks/urls.go (about)

     1  package tasks
     2  
     3  import (
     4  	"net/url"
     5  	"strings"
     6  
     7  	"github.com/huaweicloud/golangsdk"
     8  	"github.com/huaweicloud/golangsdk/openstack/utils"
     9  )
    10  
    11  const resourcePath = "tasks"
    12  
    13  func rootURL(c *golangsdk.ServiceClient) string {
    14  	return c.ServiceURL(resourcePath)
    15  }
    16  
    17  func resourceURL(c *golangsdk.ServiceClient, taskID string) string {
    18  	return c.ServiceURL(resourcePath, taskID)
    19  }
    20  
    21  func listURL(c *golangsdk.ServiceClient) string {
    22  	return rootURL(c)
    23  }
    24  
    25  func getURL(c *golangsdk.ServiceClient, taskID string) string {
    26  	return resourceURL(c, taskID)
    27  }
    28  
    29  func createURL(c *golangsdk.ServiceClient) string {
    30  	return rootURL(c)
    31  }
    32  
    33  func nextPageURL(serviceURL, requestedNext string) (string, error) {
    34  	base, err := utils.BaseEndpoint(serviceURL)
    35  	if err != nil {
    36  		return "", err
    37  	}
    38  
    39  	requestedNextURL, err := url.Parse(requestedNext)
    40  	if err != nil {
    41  		return "", err
    42  	}
    43  
    44  	base = golangsdk.NormalizeURL(base)
    45  	nextPath := base + strings.TrimPrefix(requestedNextURL.Path, "/")
    46  
    47  	nextURL, err := url.Parse(nextPath)
    48  	if err != nil {
    49  		return "", err
    50  	}
    51  
    52  	nextURL.RawQuery = requestedNextURL.RawQuery
    53  
    54  	return nextURL.String(), nil
    55  }