feat: added the Pair.

This commit is contained in:
Andrey Parhomenko 2024-05-30 00:59:36 +05:00
parent af2226a30e
commit fabcb6fd49
2 changed files with 24 additions and 5 deletions

View file

@ -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, "&")
}

View file

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