From 92fefac4404d43c53a820dd228b3a1abefaaa336 Mon Sep 17 00:00:00 2001 From: Hiep Date: Thu, 11 Jul 2024 16:24:36 +0700 Subject: [PATCH] Support add query to existing query --- pkg/httpclient/http.go | 6 ++++++ pkg/httpclient/query.go | 5 +++++ 2 files changed, 11 insertions(+) diff --git a/pkg/httpclient/http.go b/pkg/httpclient/http.go index 77e27ed..42f4d11 100644 --- a/pkg/httpclient/http.go +++ b/pkg/httpclient/http.go @@ -55,6 +55,12 @@ func NewRequestWithContext( u = u.JoinPath(path) } if query != nil { + existingQuery := u.Query() + for key, values := range existingQuery { + for _, value := range values { + query.AddString(key, value) + } + } u.RawQuery = query.String() } diff --git a/pkg/httpclient/query.go b/pkg/httpclient/query.go index 0429c46..d5000a1 100644 --- a/pkg/httpclient/query.go +++ b/pkg/httpclient/query.go @@ -37,6 +37,11 @@ func (q Query) SetString(key, value string) Query { return q } +func (q Query) AddString(key, value string) Query { + q.url().Add(key, value) + return q +} + func stringsContains(ss []string, token string) bool { for _, s := range ss { if s == token {