simple common helper to parse & return path (for hmac etc) given url

This commit is contained in:
Manuel Kreutz
2017-04-09 15:45:55 -04:00
parent bd78a39bdd
commit 7b001f710b
2 changed files with 23 additions and 0 deletions

View File

@@ -11,6 +11,7 @@ import (
"encoding/hex"
"encoding/json"
"errors"
"fmt"
"hash"
"io"
"io/ioutil"
@@ -338,3 +339,15 @@ func WriteFile(file string, data []byte) error {
}
return nil
}
// GetURIPath returns the path of a URL given a URL
func GetURIPath(uri string) string {
urip, err := url.Parse(uri)
if err != nil {
return ""
}
if urip.RawQuery != "" {
return fmt.Sprintf("%s?%s", urip.Path, urip.RawQuery)
}
return urip.Path
}