feat: added the Pair.
This commit is contained in:
parent
af2226a30e
commit
fabcb6fd49
2 changed files with 24 additions and 5 deletions
|
@ -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, "&")
|
||||
}
|
||||
|
|
|
@ -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},
|
||||
),
|
||||
)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue