feat: added the Array type for urlenc.
This commit is contained in:
parent
ccca48d237
commit
af2226a30e
3 changed files with 44 additions and 0 deletions
29
urlenc/build.go
Normal file
29
urlenc/build.go
Normal 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
11
urlenc/build_test.go
Normal 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},
|
||||
})
|
||||
}
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue