feat: added the Array type for urlenc.

This commit is contained in:
Andrey Parhomenko 2024-05-29 23:55:59 +05:00
parent ccca48d237
commit af2226a30e
3 changed files with 44 additions and 0 deletions

29
urlenc/build.go Normal file
View file

@ -0,0 +1,29 @@
package urlenc
import "strings"
import "fmt"
type Builder interface {
GetValuesURL() []string
}
type Value[V any] struct {
Name string
}
type Array[V any] struct {
Name string
Values []V
}
func (a Array[V]) String() string {
var b strings.Builder
for i, v := range a.Values {
fmt.Fprintf(&b, "%s[%d]=%v", a.Name, i, v)
if i < len(a.Values) - 1 {
fmt.Fprint(&b, "&")
}
}
return b.String()
}

11
urlenc/build_test.go Normal file
View file

@ -0,0 +1,11 @@
package urlenc
import "testing"
import "log"
func TestArray(t *testing.T) {
log.Printf("Array{...}: %s\n", Array[int]{
Name: "id",
Values: []int{123, 456, 789},
})
}

View file

@ -32,6 +32,10 @@ func Unmarshal(bts []byte, v any) error {
return nil return nil
} }
func Marshal(v any) ([]byte, error) {
return nil, nil
}
func parseStr(encodedString string, result map[string]any) error { func parseStr(encodedString string, result map[string]any) error {
// build nested map. // build nested map.
var build func(map[string]any, []string, any) error var build func(map[string]any, []string, any) error