github.com/akamai/AkamaiOPEN-edgegrid-golang/v8@v8.1.0/pkg/cps/location_url.go (about) 1 package cps 2 3 import ( 4 "errors" 5 "net/url" 6 "strconv" 7 "strings" 8 ) 9 10 var ( 11 // ErrInvalidLocation is returned when there was an error while fetching ID from location response object 12 ErrInvalidLocation = errors.New("location URL is invalid") 13 ) 14 15 // GetIDFromLocation parse the link and returns the id 16 func GetIDFromLocation(location string) (int, error) { 17 locURL, err := url.Parse(location) 18 if err != nil { 19 return 0, err 20 } 21 pathSplit := strings.Split(locURL.Path, "/") 22 idStr := pathSplit[len(pathSplit)-1] 23 id, err := strconv.Atoi(idStr) 24 if err != nil { 25 return 0, err 26 } 27 return id, nil 28 }