Skip to content

Commit d43afa1

Browse files
committed
Updated
1 parent 9cff346 commit d43afa1

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

requestopts.go

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package client
22

33
import (
4+
"fmt"
45
"net/http"
56
"net/url"
67
"path/filepath"
@@ -43,12 +44,12 @@ func OptReqEndpoint(value string) RequestOpt {
4344
}
4445

4546
// OptPath appends path elements onto a request
46-
func OptPath(value ...string) RequestOpt {
47+
func OptPath(value ...any) RequestOpt {
4748
return func(r *requestOpts) error {
4849
// Make a copy
4950
url := *r.URL
5051
// Clean up and append path
51-
url.Path = PathSeparator + filepath.Join(strings.Trim(url.Path, PathSeparator), strings.TrimPrefix(strings.Join(value, PathSeparator), PathSeparator))
52+
url.Path = PathSeparator + filepath.Join(strings.Trim(url.Path, PathSeparator), strings.TrimPrefix(join(value, PathSeparator), PathSeparator))
5253
// Set new path
5354
r.URL = &url
5455
return nil
@@ -112,3 +113,17 @@ func OptJsonStreamCallback(fn JsonStreamCallback) RequestOpt {
112113
return nil
113114
}
114115
}
116+
117+
///////////////////////////////////////////////////////////////////////////////
118+
// PRIVATE METHODS
119+
120+
func join(value []any, sep string) string {
121+
if len(value) == 0 {
122+
return ""
123+
}
124+
str := make([]string, len(value))
125+
for i, v := range value {
126+
str[i] = fmt.Sprint(v)
127+
}
128+
return strings.Join(str, sep)
129+
}

0 commit comments

Comments
 (0)