Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions requestopts.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package client

import (
"fmt"
"net/http"
"net/url"
"path/filepath"
Expand Down Expand Up @@ -43,12 +44,12 @@ func OptReqEndpoint(value string) RequestOpt {
}

// OptPath appends path elements onto a request
func OptPath(value ...string) RequestOpt {
func OptPath(value ...any) RequestOpt {
return func(r *requestOpts) error {
// Make a copy
url := *r.URL
// Clean up and append path
url.Path = PathSeparator + filepath.Join(strings.Trim(url.Path, PathSeparator), strings.TrimPrefix(strings.Join(value, PathSeparator), PathSeparator))
url.Path = PathSeparator + filepath.Join(strings.Trim(url.Path, PathSeparator), strings.TrimPrefix(join(value, PathSeparator), PathSeparator))
// Set new path
r.URL = &url
return nil
Expand Down Expand Up @@ -112,3 +113,17 @@ func OptJsonStreamCallback(fn JsonStreamCallback) RequestOpt {
return nil
}
}

///////////////////////////////////////////////////////////////////////////////
// PRIVATE METHODS

func join(value []any, sep string) string {
if len(value) == 0 {
return ""
}
str := make([]string, len(value))
for i, v := range value {
str[i] = fmt.Sprint(v)
}
return strings.Join(str, sep)
}
Loading