Skip to content

Commit a892937

Browse files
committed
Support custom query params in addition to args, filter and attrs (to allow pagination support eg. pageno=1&pagesize=10)
1 parent bf00e90 commit a892937

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

service/config.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ type FindParams struct {
4040
ArgsMap map[string]string
4141
FilterMap map[string]string
4242
AttrsMap map[string]string
43+
QueryMap map[string]string
4344
ResourceType string
4445
ResourceName string
4546
ResourceMissingErrorCode int
@@ -80,6 +81,9 @@ func constructQueryString(findParams *FindParams) string {
8081
concatQueryString(&queryBuilder, constructQueryMapString("args=", findParams.ArgsMap))
8182
concatQueryString(&queryBuilder, constructQueryMapString("filter=", findParams.FilterMap))
8283
concatQueryString(&queryBuilder, constructQueryMapString("attrs=", findParams.AttrsMap))
84+
for k, v := range findParams.QueryMap {
85+
concatQueryString(&queryBuilder, fmt.Sprintf("%s=%s", k, v))
86+
}
8387

8488
return queryBuilder.String()
8589
}

service/config_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -929,6 +929,14 @@ func TestConstructQueryString(t *testing.T) {
929929

930930
expected := "?args=bye:hello,hello:bye&filter=bye:hello,hello:bye&attrs=bye:hello,hello:bye"
931931
t.Run("CASE=8", generateTestCase(findParams, expected))
932+
933+
findParams = FindParams{
934+
FilterMap: map[string]string{"bye": "hello"},
935+
ArgsMap: map[string]string{"bye": "hello"},
936+
AttrsMap: map[string]string{"bye": "hello"},
937+
QueryMap: map[string]string{"bye": "hello"}}
938+
939+
t.Run("CASE=9", generateTestCase(findParams, "?args=bye:hello&filter=bye:hello&attrs=bye:hello&bye=hello"))
932940
}
933941

934942
func TestConstructUrlPathString(t *testing.T) {

0 commit comments

Comments
 (0)