From fabcb6fd49e86555c69c0f1a1086348370e5fa9c Mon Sep 17 00:00:00 2001 From: surdeus Date: Thu, 30 May 2024 00:59:36 +0500 Subject: [PATCH] feat: added the Pair. --- urlenc/build.go | 17 ++++++++++++----- urlenc/build_test.go | 12 ++++++++++++ 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/urlenc/build.go b/urlenc/build.go index 2e049a7..257fa31 100644 --- a/urlenc/build.go +++ b/urlenc/build.go @@ -3,12 +3,12 @@ package urlenc import "strings" import "fmt" -type Builder interface { - GetValuesURL() []string -} - -type Value[V any] struct { +type Pair[V any] struct { Name string + Value V +} +func (a Pair[V]) String() string { + return fmt.Sprintf("%s=%v", a.Name, a.Value) } type Array[V any] struct { @@ -27,3 +27,10 @@ func (a Array[V]) String() string { return b.String() } +func Join(values ...any) string { + vs := make([]string, len(values)) + for i, v := range values { + vs[i] = fmt.Sprintf("%s", v) + } + return strings.Join(vs, "&") +} diff --git a/urlenc/build_test.go b/urlenc/build_test.go index 67ac42b..d2cd85e 100644 --- a/urlenc/build_test.go +++ b/urlenc/build_test.go @@ -9,3 +9,15 @@ func TestArray(t *testing.T) { Values: []int{123, 456, 789}, }) } + +func TestJoin(t *testing.T) { + log.Printf( + Join( + Array[int]{ + "id", + []int{123, 456, 789}, + }, + Pair[int]{"somename", 25}, + ), + ) +}