From af2226a30e1edcc304cb4e6cb61359ea3cc2f859 Mon Sep 17 00:00:00 2001 From: surdeus Date: Wed, 29 May 2024 23:55:59 +0500 Subject: [PATCH] feat: added the Array type for urlenc. --- urlenc/build.go | 29 +++++++++++++++++++++++++++++ urlenc/build_test.go | 11 +++++++++++ urlenc/scan.go | 4 ++++ 3 files changed, 44 insertions(+) create mode 100644 urlenc/build.go create mode 100644 urlenc/build_test.go diff --git a/urlenc/build.go b/urlenc/build.go new file mode 100644 index 0000000..2e049a7 --- /dev/null +++ b/urlenc/build.go @@ -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() +} + diff --git a/urlenc/build_test.go b/urlenc/build_test.go new file mode 100644 index 0000000..67ac42b --- /dev/null +++ b/urlenc/build_test.go @@ -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}, + }) +} diff --git a/urlenc/scan.go b/urlenc/scan.go index 9eb899a..a849ad6 100644 --- a/urlenc/scan.go +++ b/urlenc/scan.go @@ -32,6 +32,10 @@ func Unmarshal(bts []byte, v any) error { return nil } +func Marshal(v any) ([]byte, error) { + return nil, nil +} + func parseStr(encodedString string, result map[string]any) error { // build nested map. var build func(map[string]any, []string, any) error