mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-13 15:09:42 +00:00
simple common helper to parse & return path (for hmac etc) given url
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
@@ -270,3 +270,13 @@ func TestUnixTimestampStrToTime(t *testing.T) {
|
||||
t.Error(fmt.Sprintf("Test failed. Expected '%s'. Actual '%s'.", expectedOutput, actualResult))
|
||||
}
|
||||
}
|
||||
|
||||
func TestURIPath(t *testing.T) {
|
||||
testURI := "https://api.gdax.com/accounts"
|
||||
expectedOutput := "/accounts"
|
||||
actualOutput := GetURIPath(testURI)
|
||||
if actualOutput != expectedOutput {
|
||||
t.Error(fmt.Sprintf("Test failed. Expected '%s'. Actual '%s'.",
|
||||
expectedOutput, actualOutput))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user