github.com/akamai/AkamaiOPEN-edgegrid-golang/v8@v8.1.0/pkg/papi/response_link.go (about)

     1  // Package papi provides access to the Akamai Property APIs
     2  package papi
     3  
     4  import (
     5  	"errors"
     6  	"net/url"
     7  	"strings"
     8  )
     9  
    10  var (
    11  	// ErrInvalidResponseLink is returned when there was an error while fetching ID from location response object
    12  	ErrInvalidResponseLink = errors.New("response link URL is invalid")
    13  )
    14  
    15  // ResponseLinkParse parse the link and returns the id
    16  func ResponseLinkParse(link string) (string, error) {
    17  	locURL, err := url.Parse(string(link))
    18  	if err != nil {
    19  		return "", err
    20  	}
    21  	pathSplit := strings.Split(locURL.Path, "/")
    22  	return pathSplit[len(pathSplit)-1], nil
    23  }