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}, + ), + ) +}