Debian Codegraph @

decoder.go

raw symbols SCIP
1 // Copyright 2012 The Gorilla Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
4
5 package schemascip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/
6
7 import (
8 "encodingscip-go gomod github.com/golang/go/src go1.25.0 encoding/"
9 "errorsscip-go gomod github.com/golang/go/src go1.25.0 errors/"
10 "fmtscip-go gomod github.com/golang/go/src go1.25.0 fmt/"
11 "mapsscip-go gomod github.com/golang/go/src go1.25.0 maps/"
12 "mime/multipartscip-go gomod github.com/golang/go/src go1.25.0 `mime/multipart`/"
13 "reflectscip-go gomod github.com/golang/go/src go1.25.0 reflect/"
14 "stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/"
15 "syncscip-go gomod github.com/golang/go/src go1.25.0 sync/"
16 )
17
18 const (
19 defaultMaxSizescip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/defaultMaxSize. = 16000
20 )
21
22 // errNotPointerToStruct is returned by Decode for invalid destinations;
23 // hoisted so the check does not allocate on every call.
24 var errNotPointerToStructscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/errNotPointerToStruct. = errorsscip-go gomod github.com/golang/go/src go1.25.0 errors/.Newscip-go gomod github.com/golang/go/src go1.25.0 errors/New().("schema: interface must be a pointer to struct")
25
26 var decodeValueBufferPoolscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/decodeValueBufferPool. = syncscip-go gomod github.com/golang/go/src go1.25.0 sync/.Poolscip-go gomod github.com/golang/go/src go1.25.0 sync/Pool#{
27 Newscip-go gomod github.com/golang/go/src go1.25.0 sync/Pool#New.: func() any {
28 buf := make([]reflectscip-go gomod github.com/golang/go/src go1.25.0 reflect/.Valuescip-go gomod github.com/golang/go/src go1.25.0 reflect/Value#, 0, 8)
29 return &buf
30 },
31 }
32
33 // NewDecoder returns a new Decoder.
34 func NewDecoderscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/NewDecoder().() *Decoderscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/Decoder# {
35 return &Decoderscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/Decoder#{cachescip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/Decoder#cache.: newCachescip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/newCache().(), maxSizescip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/Decoder#maxSize.: defaultMaxSizescip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/defaultMaxSize.}
36 }
37
38 // Decoder decodes values from a map[string][]string to a struct.
39 type Decoderscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/Decoder# struct {
40 cachescip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/Decoder#cache. *cachescip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/cache#
41 zeroEmptyscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/Decoder#zeroEmpty. bool
42 ignoreUnknownKeysscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/Decoder#ignoreUnknownKeys. bool
43 maxSizescip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/Decoder#maxSize. int
44 }
45
46 // SetAliasTag changes the tag used to locate custom field aliases.
47 // The default tag is "schema".
48 func (d *Decoderscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/Decoder#) SetAliasTagscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/Decoder#SetAliasTag().(tag string) {
49 d.cachescip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/Decoder#cache..lscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/cache#l..Lockscip-go gomod github.com/golang/go/src go1.25.0 sync/RWMutex#Lock().()
50 d.cachescip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/Decoder#cache..tagscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/cache#tag. = tag
51 d.cachescip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/Decoder#cache..resetscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/cache#reset().()
52 d.cachescip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/Decoder#cache..lscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/cache#l..Unlockscip-go gomod github.com/golang/go/src go1.25.0 sync/RWMutex#Unlock().()
53 }
54
55 // ZeroEmpty controls the behaviour when the decoder encounters empty values
56 // in a map.
57 // If z is true and a key in the map has the empty string as a value
58 // then the corresponding struct field is set to the zero value.
59 // If z is false then empty strings are ignored.
60 //
61 // The default value is false, that is empty values do not change
62 // the value of the struct field.
63 func (d *Decoderscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/Decoder#) ZeroEmptyscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/Decoder#ZeroEmpty().(z bool) {
64 d.zeroEmptyscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/Decoder#zeroEmpty. = z
65 }
66
67 // IgnoreUnknownKeys controls the behaviour when the decoder encounters unknown
68 // keys in the map.
69 // If i is true and an unknown field is encountered, it is ignored. This is
70 // similar to how unknown keys are handled by encoding/json.
71 // If i is false then Decode will return an error. Note that any valid keys
72 // will still be decoded in to the target struct.
73 //
74 // To preserve backwards compatibility, the default value is false.
75 func (d *Decoderscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/Decoder#) IgnoreUnknownKeysscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/Decoder#IgnoreUnknownKeys().(i bool) {
76 d.ignoreUnknownKeysscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/Decoder#ignoreUnknownKeys. = i
77 }
78
79 // MaxSize limits the size of slices for URL nested arrays or object arrays.
80 // Choose MaxSize carefully; large values may create many zero-value slice elements.
81 // Example: "items.100000=apple" would create a slice with 100,000 empty strings.
82 func (d *Decoderscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/Decoder#) MaxSizescip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/Decoder#MaxSize().(size int) {
83 d.maxSizescip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/Decoder#maxSize. = size
84 }
85
86 // RegisterConverter registers a converter function for a custom type.
87 func (d *Decoderscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/Decoder#) RegisterConverterscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/Decoder#RegisterConverter().(value interface{}, converterFunc Converterscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/Converter#) {
88 d.cachescip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/Decoder#cache..registerConverterscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/cache#registerConverter().(value, converterFunc)
89 }
90
91 // Decode decodes a map[string][]string to a struct.
92 //
93 // The first parameter must be a pointer to a struct.
94 //
95 // The second parameter is a map, typically url.Values from an HTTP request.
96 // Keys are "paths" in dotted notation to the struct fields and nested structs.
97 //
98 // See the package documentation for a full explanation of the mechanics.
99 func (d *Decoderscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/Decoder#) Decodescip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/Decoder#Decode().(dst interface{}, src map[string][]string, files ...map[string][]*multipartscip-go gomod github.com/golang/go/src go1.25.0 `mime/multipart`/.FileHeaderscip-go gomod github.com/golang/go/src go1.25.0 `mime/multipart`/FileHeader#) (err error) {
100 v := reflectscip-go gomod github.com/golang/go/src go1.25.0 reflect/.ValueOfscip-go gomod github.com/golang/go/src go1.25.0 reflect/ValueOf().(dst)
101 if v.Kindscip-go gomod github.com/golang/go/src go1.25.0 reflect/Value#Kind().() != reflectscip-go gomod github.com/golang/go/src go1.25.0 reflect/.Ptrscip-go gomod github.com/golang/go/src go1.25.0 reflect/Ptr. || v.Elemscip-go gomod github.com/golang/go/src go1.25.0 reflect/Value#Elem().().Kindscip-go gomod github.com/golang/go/src go1.25.0 reflect/Value#Kind().() != reflectscip-go gomod github.com/golang/go/src go1.25.0 reflect/.Structscip-go gomod github.com/golang/go/src go1.25.0 reflect/Struct. {
102 return errNotPointerToStructscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/errNotPointerToStruct.
103 }
104
105 // Catch panics from the decoder and return them as an error.
106 // This is needed because the decoder calls reflect and reflect panics.
107 // Installed before any other work so nothing can crash the caller.
108 defer func() {
109 if r := recover(); r != nil {
110 if e, ok := r.(error); ok {
111 err = e
112 } else {
113 err = fmtscip-go gomod github.com/golang/go/src go1.25.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.25.0 fmt/Errorf().("schema: panic while decoding: %v", r)
114 }
115 }
116 }()
117
118 var multipartFiles map[string][]*multipartscip-go gomod github.com/golang/go/src go1.25.0 `mime/multipart`/.FileHeaderscip-go gomod github.com/golang/go/src go1.25.0 `mime/multipart`/FileHeader#
119
120 if len(files) > 0 {
121 multipartFiles = files[0]
122 }
123
124 // Add files as empty string values to the decode view so path parsing
125 // works uniformly. Work on a copy: the caller's src map must not be
126 // mutated (and a caller-provided value under a file's key must not be
127 // overwritten in it).
128 if len(multipartFiles) > 0 {
129 merged := make(map[string][]string, len(src)+len(multipartFiles))
130 mapsscip-go gomod github.com/golang/go/src go1.25.0 maps/.Copyscip-go gomod github.com/golang/go/src go1.25.0 maps/Copy().(merged, src)
131 for path := range multipartFiles {
132 merged[path] = []string{""}
133 }
134 src = merged
135 }
136
137 v = v.Elemscip-go gomod github.com/golang/go/src go1.25.0 reflect/Value#Elem().()
138 t := v.Typescip-go gomod github.com/golang/go/src go1.25.0 reflect/Value#Type().()
139 rootInfo := d.cachescip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/Decoder#cache..getscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/cache#get().(t)
140 var multiErrors MultiErrorscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/MultiError#
141 for path, values := range src {
142 if parts, err := d.cachescip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/Decoder#cache..parsePathInfoscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/cache#parsePathInfo().(path, rootInfo); err == nil {
143 var filesSlice []*multipartscip-go gomod github.com/golang/go/src go1.25.0 `mime/multipart`/.FileHeaderscip-go gomod github.com/golang/go/src go1.25.0 `mime/multipart`/FileHeader#
144 if multipartFiles != nil {
145 filesSlice = multipartFiles[path]
146 }
147 if err = d.decodescip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/Decoder#decode().(v, path, parts, values, filesSlice); err != nil {
148 multiErrors = appendErrorscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/appendError().(multiErrors, path, err)
149 }
150 } else {
151 if errorsscip-go gomod github.com/golang/go/src go1.25.0 errors/.Isscip-go gomod github.com/golang/go/src go1.25.0 errors/Is().(err, errIndexTooLargescip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/errIndexTooLarge.) {
152 multiErrors = appendErrorscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/appendError().(multiErrors, path, err)
153 } else if !d.ignoreUnknownKeysscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/Decoder#ignoreUnknownKeys. {
154 multiErrors = appendErrorscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/appendError().(multiErrors, path, UnknownKeyErrorscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/UnknownKeyError#{Keyscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/UnknownKeyError#Key.: path})
155 }
156 }
157 }
158 if rootInfo.needsDefaultsWalkscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/structInfo#needsDefaultsWalk. {
159 multiErrors = mergeErrorsscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/mergeErrors().(multiErrors, d.setDefaultsscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/Decoder#setDefaults().(t, v, src, ""))
160 }
161 multiErrors = mergeErrorsscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/mergeErrors().(multiErrors, d.checkRequiredscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/Decoder#checkRequired().(rootInfo, src))
162 if len(multiErrors) > 0 {
163 return multiErrors
164 }
165 return nil
166 }
167
168 // setDefaults sets the default values when the `default` tag is specified,
169 // default is supported on basic/primitive types and their pointers,
170 // nested structs can also have default tags
171 func (d *Decoderscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/Decoder#) setDefaultsscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/Decoder#setDefaults().(t reflectscip-go gomod github.com/golang/go/src go1.25.0 reflect/.Typescip-go gomod github.com/golang/go/src go1.25.0 reflect/Type#, v reflectscip-go gomod github.com/golang/go/src go1.25.0 reflect/.Valuescip-go gomod github.com/golang/go/src go1.25.0 reflect/Value#, src map[string][]string, prefix string) MultiErrorscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/MultiError# {
172 struc := d.cachescip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/Decoder#cache..getscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/cache#get().(t)
173 // Skip the walk entirely when it can have no effect (no default tags and
174 // no anonymous embedded pointers to allocate anywhere in the tree) — the
175 // overwhelmingly common case.
176 if !struc.needsDefaultsWalkscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/structInfo#needsDefaultsWalk. {
177 return nil
178 }
179
180 var errs MultiErrorscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/MultiError#
181
182 // Allocate nil anonymous embedded pointer fields so their promoted
183 // fields stay reachable.
184 for _, idx := range struc.anonymousPtrFieldsscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/structInfo#anonymousPtrFields. {
185 if field := v.Fieldscip-go gomod github.com/golang/go/src go1.25.0 reflect/Value#Field().(idx); field.IsNilscip-go gomod github.com/golang/go/src go1.25.0 reflect/Value#IsNil().() {
186 field.Setscip-go gomod github.com/golang/go/src go1.25.0 reflect/Value#Set().(reflectscip-go gomod github.com/golang/go/src go1.25.0 reflect/.Newscip-go gomod github.com/golang/go/src go1.25.0 reflect/New().(field.Typescip-go gomod github.com/golang/go/src go1.25.0 reflect/Value#Type().().Elemscip-go gomod github.com/golang/go/src go1.25.0 reflect/Type#Elem().()))
187 }
188 }
189
190 for _, f := range struc.fieldsscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/structInfo#fields. {
191 vCurrent := walkIndexChainscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/walkIndexChain().(v, f.indexscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/fieldInfo#index.)
192 if !vCurrent.IsValidscip-go gomod github.com/golang/go/src go1.25.0 reflect/Value#IsValid().() {
193 // Unreachable behind an unsettable nil embedded pointer.
194 continue
195 }
196
197 if vCurrent.Typescip-go gomod github.com/golang/go/src go1.25.0 reflect/Value#Type().().Kindscip-go gomod github.com/golang/go/src go1.25.0 reflect/Type#Kind().() == reflectscip-go gomod github.com/golang/go/src go1.25.0 reflect/.Structscip-go gomod github.com/golang/go/src go1.25.0 reflect/Struct. && f.defaultValuescip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/fieldInfo#defaultValue. == "" {
198 errs = mergeErrorsscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/mergeErrors().(errs, d.setDefaultsscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/Decoder#setDefaults().(vCurrent.Typescip-go gomod github.com/golang/go/src go1.25.0 reflect/Value#Type().(), vCurrent, src, prefix+f.canonicalAliasscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/fieldInfo#canonicalAlias.+"."))
199 } else if isPointerToStructscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/isPointerToStruct().(vCurrent) && f.defaultValuescip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/fieldInfo#defaultValue. == "" {
200 errs = mergeErrorsscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/mergeErrors().(errs, d.setDefaultsscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/Decoder#setDefaults().(vCurrent.Elemscip-go gomod github.com/golang/go/src go1.25.0 reflect/Value#Elem().().Typescip-go gomod github.com/golang/go/src go1.25.0 reflect/Value#Type().(), vCurrent.Elemscip-go gomod github.com/golang/go/src go1.25.0 reflect/Value#Elem().(), src, prefix+f.canonicalAliasscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/fieldInfo#canonicalAlias.+"."))
201 }
202
203 if f.defaultValuescip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/fieldInfo#defaultValue. != "" && f.isRequiredscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/fieldInfo#isRequired. {
204 errs = appendErrorscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/appendError().(errs, "default-"+f.namescip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/fieldInfo#name., errorsscip-go gomod github.com/golang/go/src go1.25.0 errors/.Newscip-go gomod github.com/golang/go/src go1.25.0 errors/New().("required fields cannot have a default value"))
205 } else if f.defaultValuescip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/fieldInfo#defaultValue. != "" && vCurrent.IsZeroscip-go gomod github.com/golang/go/src go1.25.0 reflect/Value#IsZero().() && !f.isRequiredscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/fieldInfo#isRequired. && !fieldProvidedscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/fieldProvided().(src, prefix, f) {
206 if f.typscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/fieldInfo#typ..Kindscip-go gomod github.com/golang/go/src go1.25.0 reflect/Type#Kind().() == reflectscip-go gomod github.com/golang/go/src go1.25.0 reflect/.Structscip-go gomod github.com/golang/go/src go1.25.0 reflect/Struct. {
207 errs = appendErrorscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/appendError().(errs, "default-"+f.namescip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/fieldInfo#name., errorsscip-go gomod github.com/golang/go/src go1.25.0 errors/.Newscip-go gomod github.com/golang/go/src go1.25.0 errors/New().("default option is supported only on: bool, float variants, string, unit variants types or their corresponding pointers or slices"))
208 } else if f.typscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/fieldInfo#typ..Kindscip-go gomod github.com/golang/go/src go1.25.0 reflect/Type#Kind().() == reflectscip-go gomod github.com/golang/go/src go1.25.0 reflect/.Slicescip-go gomod github.com/golang/go/src go1.25.0 reflect/Slice. {
209 // check if slice has one of the supported types for defaults
210 conv := getBuiltinConverterscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/getBuiltinConverter().(f.typscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/fieldInfo#typ..Elemscip-go gomod github.com/golang/go/src go1.25.0 reflect/Type#Elem().().Kindscip-go gomod github.com/golang/go/src go1.25.0 reflect/Type#Kind().())
211 if conv == nil {
212 errs = appendErrorscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/appendError().(errs, "default-"+f.namescip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/fieldInfo#name., errorsscip-go gomod github.com/golang/go/src go1.25.0 errors/.Newscip-go gomod github.com/golang/go/src go1.25.0 errors/New().("default option is supported only on: bool, float variants, string, unit variants types or their corresponding pointers or slices"))
213 continue
214 }
215
216 elemT := f.typscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/fieldInfo#typ..Elemscip-go gomod github.com/golang/go/src go1.25.0 reflect/Type#Elem().()
217 defaultSlice := reflectscip-go gomod github.com/golang/go/src go1.25.0 reflect/.MakeSlicescip-go gomod github.com/golang/go/src go1.25.0 reflect/MakeSlice().(f.typscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/fieldInfo#typ., 0, stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.Countscip-go gomod github.com/golang/go/src go1.25.0 strings/Count().(f.defaultValuescip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/fieldInfo#defaultValue., "|")+1)
218 for val := range stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.SplitSeqscip-go gomod github.com/golang/go/src go1.25.0 strings/SplitSeq().(f.defaultValuescip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/fieldInfo#defaultValue., "|") {
219 // this check is to handle if the wrong value is provided
220 convertedVal := conv(val)
221 if !convertedVal.IsValidscip-go gomod github.com/golang/go/src go1.25.0 reflect/Value#IsValid().() {
222 errs = appendErrorscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/appendError().(errs, "default-"+f.namescip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/fieldInfo#name., fmtscip-go gomod github.com/golang/go/src go1.25.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.25.0 fmt/Errorf().("failed setting default: %s is not compatible with field %s type", val, f.namescip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/fieldInfo#name.))
223 break
224 }
225 // Builtin converters return the underlying kind; convert to
226 // the (possibly named) element type before appending, else
227 // reflect.Append panics for e.g. []MyInt.
228 defaultSlice = reflectscip-go gomod github.com/golang/go/src go1.25.0 reflect/.Appendscip-go gomod github.com/golang/go/src go1.25.0 reflect/Append().(defaultSlice, convertedVal.Convertscip-go gomod github.com/golang/go/src go1.25.0 reflect/Value#Convert().(elemT))
229 }
230 vCurrent.Setscip-go gomod github.com/golang/go/src go1.25.0 reflect/Value#Set().(defaultSlice)
231 } else if f.typscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/fieldInfo#typ..Kindscip-go gomod github.com/golang/go/src go1.25.0 reflect/Type#Kind().() == reflectscip-go gomod github.com/golang/go/src go1.25.0 reflect/.Ptrscip-go gomod github.com/golang/go/src go1.25.0 reflect/Ptr. {
232 t1 := f.typscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/fieldInfo#typ..Elemscip-go gomod github.com/golang/go/src go1.25.0 reflect/Type#Elem().()
233
234 if t1.Kindscip-go gomod github.com/golang/go/src go1.25.0 reflect/Type#Kind().() == reflectscip-go gomod github.com/golang/go/src go1.25.0 reflect/.Structscip-go gomod github.com/golang/go/src go1.25.0 reflect/Struct. || t1.Kindscip-go gomod github.com/golang/go/src go1.25.0 reflect/Type#Kind().() == reflectscip-go gomod github.com/golang/go/src go1.25.0 reflect/.Slicescip-go gomod github.com/golang/go/src go1.25.0 reflect/Slice. {
235 errs = appendErrorscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/appendError().(errs, "default-"+f.namescip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/fieldInfo#name., errorsscip-go gomod github.com/golang/go/src go1.25.0 errors/.Newscip-go gomod github.com/golang/go/src go1.25.0 errors/New().("default option is supported only on: bool, float variants, string, unit variants types or their corresponding pointers or slices"))
236 }
237
238 // this check is to handle if the wrong value is provided
239 if conv := getBuiltinConverterscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/getBuiltinConverter().(t1.Kindscip-go gomod github.com/golang/go/src go1.25.0 reflect/Type#Kind().()); conv != nil {
240 if convertedVal := conv(f.defaultValuescip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/fieldInfo#defaultValue.); convertedVal.IsValidscip-go gomod github.com/golang/go/src go1.25.0 reflect/Value#IsValid().() {
241 // Build a pointer of the field's actual element type:
242 // the converter yields the underlying kind, which is
243 // convertible to the (possibly named) element type,
244 // and *elem is assignable to the field even when the
245 // field's type is itself a named pointer type (e.g.
246 // type MyIntPtr *MyInt), where converting a *int
247 // directly would panic.
248 p := reflectscip-go gomod github.com/golang/go/src go1.25.0 reflect/.Newscip-go gomod github.com/golang/go/src go1.25.0 reflect/New().(t1)
249 p.Elemscip-go gomod github.com/golang/go/src go1.25.0 reflect/Value#Elem().().Setscip-go gomod github.com/golang/go/src go1.25.0 reflect/Value#Set().(convertedVal.Convertscip-go gomod github.com/golang/go/src go1.25.0 reflect/Value#Convert().(t1))
250 vCurrent.Setscip-go gomod github.com/golang/go/src go1.25.0 reflect/Value#Set().(p)
251 }
252 }
253 } else {
254 // this check is to handle if the wrong value is provided
255 conv := getBuiltinConverterscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/getBuiltinConverter().(f.typscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/fieldInfo#typ..Kindscip-go gomod github.com/golang/go/src go1.25.0 reflect/Type#Kind().())
256 if conv == nil {
257 errs = appendErrorscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/appendError().(errs, "default-"+f.namescip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/fieldInfo#name., errorsscip-go gomod github.com/golang/go/src go1.25.0 errors/.Newscip-go gomod github.com/golang/go/src go1.25.0 errors/New().("default option is supported only on: bool, float variants, string, unit variants types or their corresponding pointers or slices"))
258 } else if convertedVal := conv(f.defaultValuescip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/fieldInfo#defaultValue.); convertedVal.IsValidscip-go gomod github.com/golang/go/src go1.25.0 reflect/Value#IsValid().() {
259 // Builtin converters return the underlying kind; convert to
260 // the field's (possibly named) type before assigning.
261 vCurrent.Setscip-go gomod github.com/golang/go/src go1.25.0 reflect/Value#Set().(convertedVal.Convertscip-go gomod github.com/golang/go/src go1.25.0 reflect/Value#Convert().(f.typscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/fieldInfo#typ.))
262 }
263 }
264 }
265 }
266
267 return errs
268 }
269
270 func isPointerToStructscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/isPointerToStruct().(v reflectscip-go gomod github.com/golang/go/src go1.25.0 reflect/.Valuescip-go gomod github.com/golang/go/src go1.25.0 reflect/Value#) bool {
271 return !v.IsZeroscip-go gomod github.com/golang/go/src go1.25.0 reflect/Value#IsZero().() && v.Typescip-go gomod github.com/golang/go/src go1.25.0 reflect/Value#Type().().Kindscip-go gomod github.com/golang/go/src go1.25.0 reflect/Type#Kind().() == reflectscip-go gomod github.com/golang/go/src go1.25.0 reflect/.Ptrscip-go gomod github.com/golang/go/src go1.25.0 reflect/Ptr. && v.Elemscip-go gomod github.com/golang/go/src go1.25.0 reflect/Value#Elem().().Typescip-go gomod github.com/golang/go/src go1.25.0 reflect/Value#Type().().Kindscip-go gomod github.com/golang/go/src go1.25.0 reflect/Type#Kind().() == reflectscip-go gomod github.com/golang/go/src go1.25.0 reflect/.Structscip-go gomod github.com/golang/go/src go1.25.0 reflect/Struct.
272 }
273
274 func fieldProvidedscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/fieldProvided().(src map[string][]string, prefix string, f *fieldInfoscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/fieldInfo#) bool {
275 for _, p := range f.pathsscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/fieldInfo#paths().(prefix) {
276 if _, ok := src[p]; ok {
277 return true
278 }
279 }
280 return false
281 }
282
283 // checkRequired checks whether required fields are empty
284 //
285 // The set of required fields (including those of nested structs) is
286 // precomputed once per struct type in structInfo.requiredFields, so this
287 // only performs the per-request emptiness checks against src.
288 //
289 // src is the source map for decoding, we use it here to see if those required fields are included in src
290 func (d *Decoderscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/Decoder#) checkRequiredscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/Decoder#checkRequired().(info *structInfoscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/structInfo#, src map[string][]string) MultiErrorscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/MultiError# {
291 var errs MultiErrorscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/MultiError#
292 for key, fields := range info.requiredFieldsscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/structInfo#requiredFields. {
293 if isEmptyFieldsscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/isEmptyFields().(fields, src) {
294 errs = appendErrorscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/appendError().(errs, key, EmptyFieldErrorscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/EmptyFieldError#{Keyscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/EmptyFieldError#Key.: key})
295 }
296 }
297 return errs
298 }
299
300 type fieldWithPrefixscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/fieldWithPrefix# struct {
301 *fieldInfoscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/fieldWithPrefix#fieldInfo.
302 prefixscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/fieldWithPrefix#prefix. string
303 // searchPaths lists the src keys this required field answers to, and
304 // searchPathDots the corresponding nested-key prefixes; both are
305 // precomputed at cache-build time so per-request checks allocate
306 // nothing.
307 searchPathsscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/fieldWithPrefix#searchPaths. []string
308 searchPathDotsscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/fieldWithPrefix#searchPathDots. []string
309 }
310
311 func newFieldWithPrefixscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/newFieldWithPrefix().(f *fieldInfoscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/fieldInfo#, prefix string) fieldWithPrefixscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/fieldWithPrefix# {
312 paths := f.pathsscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/fieldInfo#paths().(prefix)
313 dots := make([]string, len(paths))
314 for i, p := range paths {
315 dots[i] = p + "."
316 }
317 return fieldWithPrefixscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/fieldWithPrefix#{
318 fieldInfoscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/fieldWithPrefix#fieldInfo.: f,
319 prefixscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/fieldWithPrefix#prefix.: prefix,
320 searchPathsscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/fieldWithPrefix#searchPaths.: paths,
321 searchPathDotsscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/fieldWithPrefix#searchPathDots.: dots,
322 }
323 }
324
325 // isEmptyFields returns true if all of specified fields are empty.
326 func isEmptyFieldsscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/isEmptyFields().(fields []fieldWithPrefixscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/fieldWithPrefix#, src map[string][]string) bool {
327 for _, f := range fields {
328 for i, path := range f.searchPathsscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/fieldWithPrefix#searchPaths. {
329 v, ok := src[path]
330 if ok && !isEmptyscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/isEmpty().(f.typscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/fieldInfo#typ., v) {
331 return false
332 }
333 // Check for nested keys that match this field.
334 pathDot := f.searchPathDotsscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/fieldWithPrefix#searchPathDots.[i]
335 for key, val := range src {
336 if len(val) == 0 {
337 continue
338 }
339 // for nested structs
340 if stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.HasPrefixscip-go gomod github.com/golang/go/src go1.25.0 strings/HasPrefix().(key, pathDot) {
341 if !isEmptyscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/isEmpty().(f.typscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/fieldInfo#typ., val) {
342 return false
343 }
344 }
345 }
346 }
347 }
348 return true
349 }
350
351 // isEmpty returns true if value is empty for specific type
352 func isEmptyscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/isEmpty().(t reflectscip-go gomod github.com/golang/go/src go1.25.0 reflect/.Typescip-go gomod github.com/golang/go/src go1.25.0 reflect/Type#, value []string) bool {
353 if len(value) == 0 {
354 return true
355 }
356 switch t.Kindscip-go gomod github.com/golang/go/src go1.25.0 reflect/Type#Kind().() {
357 case boolTypescip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/boolType., float32Typescip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/float32Type., float64Typescip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/float64Type.,
358 intTypescip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/intType., int8Typescip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/int8Type., int16Typescip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/int16Type., int32Typescip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/int32Type., int64Typescip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/int64Type.,
359 stringTypescip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/stringType.,
360 uintTypescip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/uintType., uint8Typescip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/uint8Type., uint16Typescip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/uint16Type., uint32Typescip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/uint32Type., uint64Typescip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/uint64Type.:
361 return len(value[0]) == 0
362 }
363 return false
364 }
365
366 var (
367 multipartFileHeaderPointerTypescip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/multipartFileHeaderPointerType. = reflectscip-go gomod github.com/golang/go/src go1.25.0 reflect/.TypeOfscip-go gomod github.com/golang/go/src go1.25.0 reflect/TypeOf().(&multipartscip-go gomod github.com/golang/go/src go1.25.0 `mime/multipart`/.FileHeaderscip-go gomod github.com/golang/go/src go1.25.0 `mime/multipart`/FileHeader#{})
368 sliceMultipartFileHeaderPointerTypescip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/sliceMultipartFileHeaderPointerType. = reflectscip-go gomod github.com/golang/go/src go1.25.0 reflect/.TypeOfscip-go gomod github.com/golang/go/src go1.25.0 reflect/TypeOf().([]*multipartscip-go gomod github.com/golang/go/src go1.25.0 `mime/multipart`/.FileHeaderscip-go gomod github.com/golang/go/src go1.25.0 `mime/multipart`/FileHeader#{})
369 )
370
371 // Supported multiple types:
372 // *multipart.FileHeader, *[]multipart.FileHeader, []*multipart.FileHeader
373 func handleMultipartFieldscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/handleMultipartField().(field reflectscip-go gomod github.com/golang/go/src go1.25.0 reflect/.Valuescip-go gomod github.com/golang/go/src go1.25.0 reflect/Value#, files []*multipartscip-go gomod github.com/golang/go/src go1.25.0 `mime/multipart`/.FileHeaderscip-go gomod github.com/golang/go/src go1.25.0 `mime/multipart`/FileHeader#) bool {
374 fieldType := field.Typescip-go gomod github.com/golang/go/src go1.25.0 reflect/Value#Type().()
375 if !isMultipartFieldscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/isMultipartField().(fieldType) {
376 return false
377 }
378
379 // Skip if files are empty and field is multipart
380 if len(files) == 0 {
381 return true
382 }
383
384 // Check for *multipart.FileHeader
385 if fieldType == multipartFileHeaderPointerTypescip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/multipartFileHeaderPointerType. {
386 field.Setscip-go gomod github.com/golang/go/src go1.25.0 reflect/Value#Set().(reflectscip-go gomod github.com/golang/go/src go1.25.0 reflect/.ValueOfscip-go gomod github.com/golang/go/src go1.25.0 reflect/ValueOf().(files[0]))
387 return true
388 }
389
390 // Check for []*multipart.FileHeader
391 if fieldType == sliceMultipartFileHeaderPointerTypescip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/sliceMultipartFileHeaderPointerType. {
392 field.Setscip-go gomod github.com/golang/go/src go1.25.0 reflect/Value#Set().(reflectscip-go gomod github.com/golang/go/src go1.25.0 reflect/.ValueOfscip-go gomod github.com/golang/go/src go1.25.0 reflect/ValueOf().(files))
393 return true
394 }
395
396 // Check for *[]*multipart.FileHeader
397 if fieldType.Kindscip-go gomod github.com/golang/go/src go1.25.0 reflect/Type#Kind().() == reflectscip-go gomod github.com/golang/go/src go1.25.0 reflect/.Pointerscip-go gomod github.com/golang/go/src go1.25.0 reflect/Pointer. {
398 fieldType = fieldType.Elemscip-go gomod github.com/golang/go/src go1.25.0 reflect/Type#Elem().()
399
400 if field.IsNilscip-go gomod github.com/golang/go/src go1.25.0 reflect/Value#IsNil().() {
401 field.Setscip-go gomod github.com/golang/go/src go1.25.0 reflect/Value#Set().(reflectscip-go gomod github.com/golang/go/src go1.25.0 reflect/.Newscip-go gomod github.com/golang/go/src go1.25.0 reflect/New().(fieldType))
402 }
403
404 if fieldType == sliceMultipartFileHeaderPointerTypescip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/sliceMultipartFileHeaderPointerType. {
405 field.Elemscip-go gomod github.com/golang/go/src go1.25.0 reflect/Value#Elem().().Setscip-go gomod github.com/golang/go/src go1.25.0 reflect/Value#Set().(reflectscip-go gomod github.com/golang/go/src go1.25.0 reflect/.ValueOfscip-go gomod github.com/golang/go/src go1.25.0 reflect/ValueOf().(files))
406 return true
407 }
408 }
409
410 return false
411 }
412
413 // Supported multiple types:
414 // *multipart.FileHeader, *[]multipart.FileHeader, []*multipart.FileHeader
415 func isMultipartFieldscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/isMultipartField().(typ reflectscip-go gomod github.com/golang/go/src go1.25.0 reflect/.Typescip-go gomod github.com/golang/go/src go1.25.0 reflect/Type#) bool {
416 // Check for *multipart.FileHeader
417 if typ == multipartFileHeaderPointerTypescip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/multipartFileHeaderPointerType. {
418 return true
419 }
420
421 // Check for []*multipart.FileHeader
422 if typ == sliceMultipartFileHeaderPointerTypescip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/sliceMultipartFileHeaderPointerType. {
423 return true
424 }
425
426 // Check for *[]*multipart.FileHeader
427 if typ.Kindscip-go gomod github.com/golang/go/src go1.25.0 reflect/Type#Kind().() == reflectscip-go gomod github.com/golang/go/src go1.25.0 reflect/.Ptrscip-go gomod github.com/golang/go/src go1.25.0 reflect/Ptr. {
428 typ = typ.Elemscip-go gomod github.com/golang/go/src go1.25.0 reflect/Type#Elem().()
429
430 if typ == sliceMultipartFileHeaderPointerTypescip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/sliceMultipartFileHeaderPointerType. {
431 return true
432 }
433 }
434
435 return false
436 }
437
438 // walkIndexChain walks v along a struct field index chain. Chains longer
439 // than one element traverse embedded structs; intermediate nil pointers are
440 // allocated so promoted fields stay reachable. It returns the zero Value
441 // when the chain is blocked by a nil pointer that cannot be set (an
442 // unexported embedded pointer), which callers treat as an unreachable
443 // field.
444 func walkIndexChainscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/walkIndexChain().(v reflectscip-go gomod github.com/golang/go/src go1.25.0 reflect/.Valuescip-go gomod github.com/golang/go/src go1.25.0 reflect/Value#, chain []int) reflectscip-go gomod github.com/golang/go/src go1.25.0 reflect/.Valuescip-go gomod github.com/golang/go/src go1.25.0 reflect/Value# {
445 for j, fi := range chain {
446 if j > 0 && v.Kindscip-go gomod github.com/golang/go/src go1.25.0 reflect/Value#Kind().() == reflectscip-go gomod github.com/golang/go/src go1.25.0 reflect/.Ptrscip-go gomod github.com/golang/go/src go1.25.0 reflect/Ptr. {
447 if v.IsNilscip-go gomod github.com/golang/go/src go1.25.0 reflect/Value#IsNil().() {
448 if !v.CanSetscip-go gomod github.com/golang/go/src go1.25.0 reflect/Value#CanSet().() {
449 return reflectscip-go gomod github.com/golang/go/src go1.25.0 reflect/.Valuescip-go gomod github.com/golang/go/src go1.25.0 reflect/Value#{}
450 }
451 v.Setscip-go gomod github.com/golang/go/src go1.25.0 reflect/Value#Set().(reflectscip-go gomod github.com/golang/go/src go1.25.0 reflect/.Newscip-go gomod github.com/golang/go/src go1.25.0 reflect/New().(v.Typescip-go gomod github.com/golang/go/src go1.25.0 reflect/Value#Type().().Elemscip-go gomod github.com/golang/go/src go1.25.0 reflect/Type#Elem().()))
452 }
453 v = v.Elemscip-go gomod github.com/golang/go/src go1.25.0 reflect/Value#Elem().()
454 }
455 v = v.Fieldscip-go gomod github.com/golang/go/src go1.25.0 reflect/Value#Field().(fi)
456 }
457 return v
458 }
459
460 // decode fills a struct field using a parsed path.
461 func (d *Decoderscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/Decoder#) decodescip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/Decoder#decode().(v reflectscip-go gomod github.com/golang/go/src go1.25.0 reflect/.Valuescip-go gomod github.com/golang/go/src go1.25.0 reflect/Value#, path string, parts []pathPartscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/pathPart#, values []string, files []*multipartscip-go gomod github.com/golang/go/src go1.25.0 `mime/multipart`/.FileHeaderscip-go gomod github.com/golang/go/src go1.25.0 `mime/multipart`/FileHeader#) error {
462 // Get the field walking the struct fields by index.
463 for _, hop := range parts[0].hopsscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/pathPart#hops. {
464 // A previous hop may have been blocked by an unsettable nil
465 // embedded pointer; the field is unreachable then.
466 if !v.IsValidscip-go gomod github.com/golang/go/src go1.25.0 reflect/Value#IsValid().() {
467 return nil
468 }
469 if v.Kindscip-go gomod github.com/golang/go/src go1.25.0 reflect/Value#Kind().() == reflectscip-go gomod github.com/golang/go/src go1.25.0 reflect/.Ptrscip-go gomod github.com/golang/go/src go1.25.0 reflect/Ptr. {
470 if v.IsNilscip-go gomod github.com/golang/go/src go1.25.0 reflect/Value#IsNil().() {
471 v.Setscip-go gomod github.com/golang/go/src go1.25.0 reflect/Value#Set().(reflectscip-go gomod github.com/golang/go/src go1.25.0 reflect/.Newscip-go gomod github.com/golang/go/src go1.25.0 reflect/New().(v.Typescip-go gomod github.com/golang/go/src go1.25.0 reflect/Value#Type().().Elemscip-go gomod github.com/golang/go/src go1.25.0 reflect/Type#Elem().()))
472 }
473 v = v.Elemscip-go gomod github.com/golang/go/src go1.25.0 reflect/Value#Elem().()
474 }
475
476 // Allocate embedded anonymous pointers required for promoted fields.
477 for _, idx := range hop.ensurescip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/pathHop#ensure. {
478 if f := v.Fieldscip-go gomod github.com/golang/go/src go1.25.0 reflect/Value#Field().(idx); f.IsNilscip-go gomod github.com/golang/go/src go1.25.0 reflect/Value#IsNil().() {
479 f.Setscip-go gomod github.com/golang/go/src go1.25.0 reflect/Value#Set().(reflectscip-go gomod github.com/golang/go/src go1.25.0 reflect/.Newscip-go gomod github.com/golang/go/src go1.25.0 reflect/New().(f.Typescip-go gomod github.com/golang/go/src go1.25.0 reflect/Value#Type().().Elemscip-go gomod github.com/golang/go/src go1.25.0 reflect/Type#Elem().()))
480 }
481 }
482
483 v = walkIndexChainscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/walkIndexChain().(v, hop.indexscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/pathHop#index.)
484 }
485
486 // Don't even bother for unexported fields.
487 if !v.CanSetscip-go gomod github.com/golang/go/src go1.25.0 reflect/Value#CanSet().() {
488 return nil
489 }
490
491 // Fast path: plain builtin scalar fields skip the converter/unmarshaler
492 // dispatch below; fastKind was validated at cache-build time.
493 if k := parts[0].fieldscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/pathPart#field..fastKindscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/fieldInfo#fastKind.; k != reflectscip-go gomod github.com/golang/go/src go1.25.0 reflect/.Invalidscip-go gomod github.com/golang/go/src go1.25.0 reflect/Invalid. && len(parts) == 1 && !parts[0].elemscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/pathPart#elem. {
494 val := ""
495 if len(values) > 0 {
496 val = values[len(values)-1]
497 }
498 if val == "" {
499 if d.zeroEmptyscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/Decoder#zeroEmpty. {
500 v.SetZeroscip-go gomod github.com/golang/go/src go1.25.0 reflect/Value#SetZero().()
501 }
502 return nil
503 }
504 if _, ok := setBuiltinKindscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/setBuiltinKind().(v, k, val); !ok {
505 return ConversionErrorscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/ConversionError#{
506 Keyscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/ConversionError#Key.: path,
507 Typescip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/ConversionError#Type.: parts[0].fieldscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/pathPart#field..typscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/fieldInfo#typ.,
508 Indexscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/ConversionError#Index.: -1,
509 }
510 }
511 return nil
512 }
513
514 // Check multipart files
515 if parts[0].fieldscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/pathPart#field..isMultipartscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/fieldInfo#isMultipart. && handleMultipartFieldscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/handleMultipartField().(v, files) {
516 return nil
517 }
518
519 // Dereference if needed.
520 t := v.Typescip-go gomod github.com/golang/go/src go1.25.0 reflect/Value#Type().()
521 if t.Kindscip-go gomod github.com/golang/go/src go1.25.0 reflect/Type#Kind().() == reflectscip-go gomod github.com/golang/go/src go1.25.0 reflect/.Ptrscip-go gomod github.com/golang/go/src go1.25.0 reflect/Ptr. {
522 t = t.Elemscip-go gomod github.com/golang/go/src go1.25.0 reflect/Type#Elem().()
523 if v.IsNilscip-go gomod github.com/golang/go/src go1.25.0 reflect/Value#IsNil().() {
524 v.Setscip-go gomod github.com/golang/go/src go1.25.0 reflect/Value#Set().(reflectscip-go gomod github.com/golang/go/src go1.25.0 reflect/.Newscip-go gomod github.com/golang/go/src go1.25.0 reflect/New().(t))
525 }
526 v = v.Elemscip-go gomod github.com/golang/go/src go1.25.0 reflect/Value#Elem().()
527 }
528
529 // Slice of structs. Let's go recursive.
530 if len(parts) > 1 {
531 idx := parts[0].indexscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/pathPart#index.
532 // a defensive check to avoid creating a large slice based on user input index
533 if idx > d.maxSizescip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/Decoder#maxSize. {
534 return fmtscip-go gomod github.com/golang/go/src go1.25.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.25.0 fmt/Errorf().("%v index %d is larger than the configured maxSize %d", v.Kindscip-go gomod github.com/golang/go/src go1.25.0 reflect/Value#Kind().(), idx, d.maxSizescip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/Decoder#maxSize.)
535 }
536 if v.IsNilscip-go gomod github.com/golang/go/src go1.25.0 reflect/Value#IsNil().() || v.Lenscip-go gomod github.com/golang/go/src go1.25.0 reflect/Value#Len().() < idx+1 {
537 // Grow into a fresh backing array: extending within existing
538 // capacity would write into memory the caller may still share
539 // through other slices aliasing the original array.
540 value := reflectscip-go gomod github.com/golang/go/src go1.25.0 reflect/.MakeSlicescip-go gomod github.com/golang/go/src go1.25.0 reflect/MakeSlice().(t, idx+1, idx+1)
541 if v.Lenscip-go gomod github.com/golang/go/src go1.25.0 reflect/Value#Len().() > 0 {
542 // Resize it.
543 reflectscip-go gomod github.com/golang/go/src go1.25.0 reflect/.Copyscip-go gomod github.com/golang/go/src go1.25.0 reflect/Copy().(value, v)
544 }
545 v.Setscip-go gomod github.com/golang/go/src go1.25.0 reflect/Value#Set().(value)
546 }
547 return d.decodescip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/Decoder#decode().(v.Indexscip-go gomod github.com/golang/go/src go1.25.0 reflect/Value#Index().(idx), path, parts[1:], values, files)
548 }
549
550 // Get the converter early in case there is one for a slice type.
551 conv := d.cachescip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/Decoder#cache..converterscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/cache#converter().(t)
552 // The encoding.TextUnmarshaler facts for v's type are precomputed per
553 // field; instances are bound to live values where needed below. For an
554 // elem part (path terminated at a slice index) v is an element of the
555 // slice field, so the element type's facts apply.
556 m := parts[0].fieldscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/pathPart#field..derefUnmarshalerscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/fieldInfo#derefUnmarshaler.
557 if parts[0].elemscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/pathPart#elem. {
558 m = parts[0].fieldscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/pathPart#field..elemUnmarshalerscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/fieldInfo#elemUnmarshaler.
559 }
560 if conv == nil && t.Kindscip-go gomod github.com/golang/go/src go1.25.0 reflect/Type#Kind().() == reflectscip-go gomod github.com/golang/go/src go1.25.0 reflect/.Slicescip-go gomod github.com/golang/go/src go1.25.0 reflect/Slice. && m.IsSliceElementscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/unmarshaler#IsSliceElement. {
561 elemT := t.Elemscip-go gomod github.com/golang/go/src go1.25.0 reflect/Type#Elem().()
562 isPtrElem := elemT.Kindscip-go gomod github.com/golang/go/src go1.25.0 reflect/Type#Kind().() == reflectscip-go gomod github.com/golang/go/src go1.25.0 reflect/.Ptrscip-go gomod github.com/golang/go/src go1.25.0 reflect/Ptr.
563 if isPtrElem {
564 elemT = elemT.Elemscip-go gomod github.com/golang/go/src go1.25.0 reflect/Type#Elem().()
565 }
566
567 // Try to get a converter for the element type.
568 customConv := d.cachescip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/Decoder#cache..converterscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/cache#converter().(elemT)
569 conv := customConv
570 if conv == nil {
571 conv = getBuiltinConverterscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/getBuiltinConverter().(elemT.Kindscip-go gomod github.com/golang/go/src go1.25.0 reflect/Type#Kind().())
572 if conv == nil {
573 // As we are not dealing with slice of structs here, we don't need to check if the type
574 // implements TextUnmarshaler interface
575 return fmtscip-go gomod github.com/golang/go/src go1.25.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.25.0 fmt/Errorf().("schema: converter not found for %v", elemT)
576 }
577 }
578
579 // Fast path: builtin element kinds without unmarshalers, custom
580 // converters or pointer elements decode straight into a fresh slice,
581 // avoiding one reflect.Value allocation per element.
582 if customConv == nil && !m.IsValidscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/unmarshaler#IsValid. && !isPtrElem {
583 return d.decodeBuiltinSlicescip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/Decoder#decodeBuiltinSlice().(v, t, path, values)
584 }
585
586 itemsBuf := decodeValueBufferPoolscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/decodeValueBufferPool..Getscip-go gomod github.com/golang/go/src go1.25.0 sync/Pool#Get().().(*[]reflectscip-go gomod github.com/golang/go/src go1.25.0 reflect/.Valuescip-go gomod github.com/golang/go/src go1.25.0 reflect/Value#)
587 items := (*itemsBuf)[:0]
588 defer func() {
589 clear(items)
590 *itemsBuf = items[:0]
591 decodeValueBufferPoolscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/decodeValueBufferPool..Putscip-go gomod github.com/golang/go/src go1.25.0 sync/Pool#Put().(itemsBuf)
592 }()
593
594 for key, value := range values {
595 if value == "" {
596 if d.zeroEmptyscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/Decoder#zeroEmpty. {
597 items = append(items, reflectscip-go gomod github.com/golang/go/src go1.25.0 reflect/.Zeroscip-go gomod github.com/golang/go/src go1.25.0 reflect/Zero().(t.Elemscip-go gomod github.com/golang/go/src go1.25.0 reflect/Type#Elem().()))
598 }
599 } else if m.IsValidscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/unmarshaler#IsValid. {
600 u := reflectscip-go gomod github.com/golang/go/src go1.25.0 reflect/.Newscip-go gomod github.com/golang/go/src go1.25.0 reflect/New().(elemT)
601 if m.IsSliceElementPtrscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/unmarshaler#IsSliceElementPtr. {
602 u = reflectscip-go gomod github.com/golang/go/src go1.25.0 reflect/.Newscip-go gomod github.com/golang/go/src go1.25.0 reflect/New().(reflectscip-go gomod github.com/golang/go/src go1.25.0 reflect/.PointerToscip-go gomod github.com/golang/go/src go1.25.0 reflect/PointerTo().(elemT).Elemscip-go gomod github.com/golang/go/src go1.25.0 reflect/Type#Elem().())
603 }
604 um, _ := reflectscip-go gomod github.com/golang/go/src go1.25.0 reflect/.TypeAssertscip-go gomod github.com/golang/go/src go1.25.0 reflect/TypeAssert().[encodingscip-go gomod github.com/golang/go/src go1.25.0 encoding/.TextUnmarshalerscip-go gomod github.com/golang/go/src go1.25.0 encoding/TextUnmarshaler#](u)
605 if err := um.UnmarshalTextscip-go gomod github.com/golang/go/src go1.25.0 encoding/TextUnmarshaler#UnmarshalText().([]byte(value)); err != nil {
606 return ConversionErrorscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/ConversionError#{
607 Keyscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/ConversionError#Key.: path,
608 Typescip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/ConversionError#Type.: t,
609 Indexscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/ConversionError#Index.: key,
610 Errscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/ConversionError#Err.: err,
611 }
612 }
613 if m.IsSliceElementPtrscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/unmarshaler#IsSliceElementPtr. {
614 items = append(items, u.Elemscip-go gomod github.com/golang/go/src go1.25.0 reflect/Value#Elem().().Addrscip-go gomod github.com/golang/go/src go1.25.0 reflect/Value#Addr().())
615 } else {
616 // u is always a pointer from reflect.New; store the
617 // pointed-to value.
618 items = append(items, u.Elemscip-go gomod github.com/golang/go/src go1.25.0 reflect/Value#Elem().())
619 }
620 } else if item := conv(value); item.IsValidscip-go gomod github.com/golang/go/src go1.25.0 reflect/Value#IsValid().() {
621 items = appendConvertedItemscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/appendConvertedItem().(items, item, elemT, isPtrElem)
622 } else {
623 if stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.IndexBytescip-go gomod github.com/golang/go/src go1.25.0 strings/IndexByte().(value, ',') != -1 {
624 for value := range stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.SplitSeqscip-go gomod github.com/golang/go/src go1.25.0 strings/SplitSeq().(value, ",") {
625 if value == "" {
626 if d.zeroEmptyscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/Decoder#zeroEmpty. {
627 items = append(items, reflectscip-go gomod github.com/golang/go/src go1.25.0 reflect/.Zeroscip-go gomod github.com/golang/go/src go1.25.0 reflect/Zero().(t.Elemscip-go gomod github.com/golang/go/src go1.25.0 reflect/Type#Elem().()))
628 }
629 } else if item := conv(value); item.IsValidscip-go gomod github.com/golang/go/src go1.25.0 reflect/Value#IsValid().() {
630 items = appendConvertedItemscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/appendConvertedItem().(items, item, elemT, isPtrElem)
631 } else {
632 return ConversionErrorscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/ConversionError#{
633 Keyscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/ConversionError#Key.: path,
634 Typescip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/ConversionError#Type.: elemT,
635 Indexscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/ConversionError#Index.: key,
636 }
637 }
638 }
639 } else {
640 return ConversionErrorscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/ConversionError#{
641 Keyscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/ConversionError#Key.: path,
642 Typescip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/ConversionError#Type.: elemT,
643 Indexscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/ConversionError#Index.: key,
644 }
645 }
646 }
647 }
648 value := reflectscip-go gomod github.com/golang/go/src go1.25.0 reflect/.MakeSlicescip-go gomod github.com/golang/go/src go1.25.0 reflect/MakeSlice().(t, len(items), len(items))
649 for i, item := range items {
650 value.Indexscip-go gomod github.com/golang/go/src go1.25.0 reflect/Value#Index().(i).Setscip-go gomod github.com/golang/go/src go1.25.0 reflect/Value#Set().(item)
651 }
652 v.Setscip-go gomod github.com/golang/go/src go1.25.0 reflect/Value#Set().(value)
653 } else {
654 val := ""
655 // Use the last value provided if any values were provided
656 if len(values) > 0 {
657 val = values[len(values)-1]
658 }
659
660 if conv != nil {
661 if value := conv(val); value.IsValidscip-go gomod github.com/golang/go/src go1.25.0 reflect/Value#IsValid().() {
662 v.Setscip-go gomod github.com/golang/go/src go1.25.0 reflect/Value#Set().(value.Convertscip-go gomod github.com/golang/go/src go1.25.0 reflect/Value#Convert().(t))
663 } else {
664 return ConversionErrorscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/ConversionError#{
665 Keyscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/ConversionError#Key.: path,
666 Typescip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/ConversionError#Type.: t,
667 Indexscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/ConversionError#Index.: -1,
668 }
669 }
670 } else if m.IsValidscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/unmarshaler#IsValid. {
671 if m.IsPtrscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/unmarshaler#IsPtr. {
672 u := reflectscip-go gomod github.com/golang/go/src go1.25.0 reflect/.Newscip-go gomod github.com/golang/go/src go1.25.0 reflect/New().(v.Typescip-go gomod github.com/golang/go/src go1.25.0 reflect/Value#Type().())
673 um, _ := reflectscip-go gomod github.com/golang/go/src go1.25.0 reflect/.TypeAssertscip-go gomod github.com/golang/go/src go1.25.0 reflect/TypeAssert().[encodingscip-go gomod github.com/golang/go/src go1.25.0 encoding/.TextUnmarshalerscip-go gomod github.com/golang/go/src go1.25.0 encoding/TextUnmarshaler#](u)
674 if err := um.UnmarshalTextscip-go gomod github.com/golang/go/src go1.25.0 encoding/TextUnmarshaler#UnmarshalText().([]byte(val)); err != nil {
675 return ConversionErrorscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/ConversionError#{
676 Keyscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/ConversionError#Key.: path,
677 Typescip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/ConversionError#Type.: t,
678 Indexscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/ConversionError#Index.: -1,
679 Errscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/ConversionError#Err.: err,
680 }
681 }
682 v.Setscip-go gomod github.com/golang/go/src go1.25.0 reflect/Value#Set().(reflectscip-go gomod github.com/golang/go/src go1.25.0 reflect/.Indirectscip-go gomod github.com/golang/go/src go1.25.0 reflect/Indirect().(u))
683 } else {
684 // If the value implements the encoding.TextUnmarshaler interface
685 // apply UnmarshalText as the converter, binding it to the
686 // live value.
687 um, _ := reflectscip-go gomod github.com/golang/go/src go1.25.0 reflect/.TypeAssertscip-go gomod github.com/golang/go/src go1.25.0 reflect/TypeAssert().[encodingscip-go gomod github.com/golang/go/src go1.25.0 encoding/.TextUnmarshalerscip-go gomod github.com/golang/go/src go1.25.0 encoding/TextUnmarshaler#](v)
688 if err := um.UnmarshalTextscip-go gomod github.com/golang/go/src go1.25.0 encoding/TextUnmarshaler#UnmarshalText().([]byte(val)); err != nil {
689 return ConversionErrorscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/ConversionError#{
690 Keyscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/ConversionError#Key.: path,
691 Typescip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/ConversionError#Type.: t,
692 Indexscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/ConversionError#Index.: -1,
693 Errscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/ConversionError#Err.: err,
694 }
695 }
696 }
697 } else if val == "" {
698 if d.zeroEmptyscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/Decoder#zeroEmpty. {
699 v.Setscip-go gomod github.com/golang/go/src go1.25.0 reflect/Value#Set().(reflectscip-go gomod github.com/golang/go/src go1.25.0 reflect/.Zeroscip-go gomod github.com/golang/go/src go1.25.0 reflect/Zero().(t))
700 }
701 } else if handled, ok := setBuiltinKindscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/setBuiltinKind().(v, t.Kindscip-go gomod github.com/golang/go/src go1.25.0 reflect/Type#Kind().(), val); handled {
702 if !ok {
703 return ConversionErrorscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/ConversionError#{
704 Keyscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/ConversionError#Key.: path,
705 Typescip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/ConversionError#Type.: t,
706 Indexscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/ConversionError#Index.: -1,
707 }
708 }
709 } else {
710 return fmtscip-go gomod github.com/golang/go/src go1.25.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.25.0 fmt/Errorf().("schema: converter not found for %v", t)
711 }
712 }
713 return nil
714 }
715
716 // appendConvertedItem converts a builtin/custom converter result to the slice
717 // element type and appends it, wrapping it in a freshly allocated pointer for
718 // pointer-element slices. The conversion must happen before the pointer wrap:
719 // builtin converters return the underlying kind (e.g. int for a named
720 // `type MyInt int`), which is not assignable to the named element type, so
721 // Set-ing it into a *MyInt without converting first panics.
722 func appendConvertedItemscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/appendConvertedItem().(items []reflectscip-go gomod github.com/golang/go/src go1.25.0 reflect/.Valuescip-go gomod github.com/golang/go/src go1.25.0 reflect/Value#, item reflectscip-go gomod github.com/golang/go/src go1.25.0 reflect/.Valuescip-go gomod github.com/golang/go/src go1.25.0 reflect/Value#, elemT reflectscip-go gomod github.com/golang/go/src go1.25.0 reflect/.Typescip-go gomod github.com/golang/go/src go1.25.0 reflect/Type#, isPtrElem bool) []reflectscip-go gomod github.com/golang/go/src go1.25.0 reflect/.Valuescip-go gomod github.com/golang/go/src go1.25.0 reflect/Value# {
723 if item.Typescip-go gomod github.com/golang/go/src go1.25.0 reflect/Value#Type().() != elemT {
724 item = item.Convertscip-go gomod github.com/golang/go/src go1.25.0 reflect/Value#Convert().(elemT)
725 }
726 if isPtrElem {
727 ptr := reflectscip-go gomod github.com/golang/go/src go1.25.0 reflect/.Newscip-go gomod github.com/golang/go/src go1.25.0 reflect/New().(elemT)
728 ptr.Elemscip-go gomod github.com/golang/go/src go1.25.0 reflect/Value#Elem().().Setscip-go gomod github.com/golang/go/src go1.25.0 reflect/Value#Set().(item)
729 item = ptr
730 }
731 return append(items, item)
732 }
733
734 // decodeBuiltinSlice decodes values into the slice field v of type t whose
735 // elements are builtin-convertible kinds, parsing directly into slice slots
736 // instead of boxing every element in a reflect.Value. The slice is built
737 // detached and only assigned to v when every value parsed, matching the
738 // all-or-nothing behavior of the generic path.
739 //
740 // A value that fails to parse as a whole is retried as a comma-separated
741 // list. For non-string kinds a value containing a comma can never parse as a
742 // whole (no builtin syntax admits commas — pinned by a test), and string
743 // values always parse, so item boundaries are knowable upfront: the slice is
744 // sized by a cheap comma count (an upper bound, since empty items may be
745 // skipped) and truncated to the filled length at the end.
746 func (d *Decoderscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/Decoder#) decodeBuiltinSlicescip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/Decoder#decodeBuiltinSlice().(v reflectscip-go gomod github.com/golang/go/src go1.25.0 reflect/.Valuescip-go gomod github.com/golang/go/src go1.25.0 reflect/Value#, t reflectscip-go gomod github.com/golang/go/src go1.25.0 reflect/.Typescip-go gomod github.com/golang/go/src go1.25.0 reflect/Type#, path string, values []string) error {
747 elemT := t.Elemscip-go gomod github.com/golang/go/src go1.25.0 reflect/Type#Elem().()
748 k := elemT.Kindscip-go gomod github.com/golang/go/src go1.25.0 reflect/Type#Kind().()
749 split := k != reflectscip-go gomod github.com/golang/go/src go1.25.0 reflect/.Stringscip-go gomod github.com/golang/go/src go1.25.0 reflect/String.
750
751 n := 0
752 for _, value := range values {
753 if split {
754 n += stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.Countscip-go gomod github.com/golang/go/src go1.25.0 strings/Count().(value, ",")
755 }
756 n++
757 }
758
759 // Exact builtin slice types decode without per-element reflect calls;
760 // named slice or element types fall through to the generic path.
761 switch t {
762 case typSliceStringscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/typSliceString.:
763 return decodeNativeSlicescip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/decodeNativeSlice().(d.zeroEmptyscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/Decoder#zeroEmpty., v, path, values, elemT, n, split, parseNativeStringscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/parseNativeString().)
764 case typSliceIntscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/typSliceInt.:
765 return decodeNativeSlicescip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/decodeNativeSlice().(d.zeroEmptyscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/Decoder#zeroEmpty., v, path, values, elemT, n, split, parseNativeIntscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/parseNativeInt().)
766 case typSliceInt64scip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/typSliceInt64.:
767 return decodeNativeSlicescip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/decodeNativeSlice().(d.zeroEmptyscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/Decoder#zeroEmpty., v, path, values, elemT, n, split, parseNativeInt64scip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/parseNativeInt64().)
768 case typSliceUintscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/typSliceUint.:
769 return decodeNativeSlicescip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/decodeNativeSlice().(d.zeroEmptyscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/Decoder#zeroEmpty., v, path, values, elemT, n, split, parseNativeUintscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/parseNativeUint().)
770 case typSliceUint64scip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/typSliceUint64.:
771 return decodeNativeSlicescip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/decodeNativeSlice().(d.zeroEmptyscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/Decoder#zeroEmpty., v, path, values, elemT, n, split, parseNativeUint64scip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/parseNativeUint64().)
772 case typSliceFloat64scip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/typSliceFloat64.:
773 return decodeNativeSlicescip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/decodeNativeSlice().(d.zeroEmptyscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/Decoder#zeroEmpty., v, path, values, elemT, n, split, parseNativeFloat64scip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/parseNativeFloat64().)
774 case typSliceBoolscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/typSliceBool.:
775 return decodeNativeSlicescip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/decodeNativeSlice().(d.zeroEmptyscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/Decoder#zeroEmpty., v, path, values, elemT, n, split, parseNativeBoolscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/parseNativeBool().)
776 }
777
778 sl := reflectscip-go gomod github.com/golang/go/src go1.25.0 reflect/.MakeSlicescip-go gomod github.com/golang/go/src go1.25.0 reflect/MakeSlice().(t, n, n)
779 i := 0
780 for key, value := range values {
781 switch {
782 case value == "":
783 if d.zeroEmptyscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/Decoder#zeroEmpty. {
784 i++ // slot stays zero
785 }
786 case split && stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.IndexBytescip-go gomod github.com/golang/go/src go1.25.0 strings/IndexByte().(value, ',') != -1:
787 for item := range stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.SplitSeqscip-go gomod github.com/golang/go/src go1.25.0 strings/SplitSeq().(value, ",") {
788 if item == "" {
789 if d.zeroEmptyscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/Decoder#zeroEmpty. {
790 i++ // slot stays zero
791 }
792 continue
793 }
794 if _, ok := setBuiltinKindscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/setBuiltinKind().(sl.Indexscip-go gomod github.com/golang/go/src go1.25.0 reflect/Value#Index().(i), k, item); !ok {
795 return ConversionErrorscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/ConversionError#{
796 Keyscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/ConversionError#Key.: path,
797 Typescip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/ConversionError#Type.: elemT,
798 Indexscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/ConversionError#Index.: key,
799 }
800 }
801 i++
802 }
803 default:
804 if _, ok := setBuiltinKindscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/setBuiltinKind().(sl.Indexscip-go gomod github.com/golang/go/src go1.25.0 reflect/Value#Index().(i), k, value); !ok {
805 return ConversionErrorscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/ConversionError#{
806 Keyscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/ConversionError#Key.: path,
807 Typescip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/ConversionError#Type.: elemT,
808 Indexscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/ConversionError#Index.: key,
809 }
810 }
811 i++
812 }
813 }
814 if i < n {
815 sl = sl.Slicescip-go gomod github.com/golang/go/src go1.25.0 reflect/Value#Slice().(0, i)
816 }
817 v.Setscip-go gomod github.com/golang/go/src go1.25.0 reflect/Value#Set().(sl)
818 return nil
819 }
820
821 // Exact (unnamed) builtin slice types eligible for the native decode path.
822 var (
823 typSliceStringscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/typSliceString. = reflectscip-go gomod github.com/golang/go/src go1.25.0 reflect/.TypeOfscip-go gomod github.com/golang/go/src go1.25.0 reflect/TypeOf().([]string(nil))
824 typSliceIntscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/typSliceInt. = reflectscip-go gomod github.com/golang/go/src go1.25.0 reflect/.TypeOfscip-go gomod github.com/golang/go/src go1.25.0 reflect/TypeOf().([]int(nil))
825 typSliceInt64scip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/typSliceInt64. = reflectscip-go gomod github.com/golang/go/src go1.25.0 reflect/.TypeOfscip-go gomod github.com/golang/go/src go1.25.0 reflect/TypeOf().([]int64(nil))
826 typSliceUintscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/typSliceUint. = reflectscip-go gomod github.com/golang/go/src go1.25.0 reflect/.TypeOfscip-go gomod github.com/golang/go/src go1.25.0 reflect/TypeOf().([]uint(nil))
827 typSliceUint64scip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/typSliceUint64. = reflectscip-go gomod github.com/golang/go/src go1.25.0 reflect/.TypeOfscip-go gomod github.com/golang/go/src go1.25.0 reflect/TypeOf().([]uint64(nil))
828 typSliceFloat64scip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/typSliceFloat64. = reflectscip-go gomod github.com/golang/go/src go1.25.0 reflect/.TypeOfscip-go gomod github.com/golang/go/src go1.25.0 reflect/TypeOf().([]float64(nil))
829 typSliceBoolscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/typSliceBool. = reflectscip-go gomod github.com/golang/go/src go1.25.0 reflect/.TypeOfscip-go gomod github.com/golang/go/src go1.25.0 reflect/TypeOf().([]bool(nil))
830 )
831
832 // decodeNativeSlice mirrors the generic decodeBuiltinSlice loop for a field
833 // typed exactly []T, parsing into a native slice assigned only if every value
834 // parsed (all-or-nothing). n is the precomputed element upper bound.
835 func decodeNativeSlicescip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/decodeNativeSlice().[T any](zeroEmpty bool, v reflectscip-go gomod github.com/golang/go/src go1.25.0 reflect/.Valuescip-go gomod github.com/golang/go/src go1.25.0 reflect/Value#, path string, values []string, elemT reflectscip-go gomod github.com/golang/go/src go1.25.0 reflect/.Typescip-go gomod github.com/golang/go/src go1.25.0 reflect/Type#, n int, split bool, parse func(string) (T, bool)) error {
836 out := make([]T, 0, n)
837 var zero T
838 for key, value := range values {
839 switch {
840 case value == "":
841 if zeroEmpty {
842 out = append(out, zero)
843 }
844 case split && stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.IndexBytescip-go gomod github.com/golang/go/src go1.25.0 strings/IndexByte().(value, ',') != -1:
845 for item := range stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.SplitSeqscip-go gomod github.com/golang/go/src go1.25.0 strings/SplitSeq().(value, ",") {
846 if item == "" {
847 if zeroEmpty {
848 out = append(out, zero)
849 }
850 continue
851 }
852 ev, ok := parse(item)
853 if !ok {
854 return ConversionErrorscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/ConversionError#{
855 Keyscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/ConversionError#Key.: path,
856 Typescip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/ConversionError#Type.: elemT,
857 Indexscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/ConversionError#Index.: key,
858 }
859 }
860 out = append(out, ev)
861 }
862 default:
863 ev, ok := parse(value)
864 if !ok {
865 return ConversionErrorscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/ConversionError#{
866 Keyscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/ConversionError#Key.: path,
867 Typescip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/ConversionError#Type.: elemT,
868 Indexscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/ConversionError#Index.: key,
869 }
870 }
871 out = append(out, ev)
872 }
873 }
874 // v's type is exactly []T here (the dispatch switch guarantees it), so
875 // assign through the typed pointer: no reflect.ValueOf escape, no Set
876 // assignability checks, and a loud panic if the invariant is ever broken.
877 *v.Addrscip-go gomod github.com/golang/go/src go1.25.0 reflect/Value#Addr().().Interfacescip-go gomod github.com/golang/go/src go1.25.0 reflect/Value#Interface().().(*[]T) = out
878 return nil
879 }
880
881 func isTextUnmarshalerscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/isTextUnmarshaler().(v reflectscip-go gomod github.com/golang/go/src go1.25.0 reflect/.Valuescip-go gomod github.com/golang/go/src go1.25.0 reflect/Value#) unmarshalerscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/unmarshaler# {
882 // Create a new unmarshaller instance
883 m := unmarshalerscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/unmarshaler#{}
884 if _, m.IsValidscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/unmarshaler#IsValid. = reflectscip-go gomod github.com/golang/go/src go1.25.0 reflect/.TypeAssertscip-go gomod github.com/golang/go/src go1.25.0 reflect/TypeAssert().[encodingscip-go gomod github.com/golang/go/src go1.25.0 encoding/.TextUnmarshalerscip-go gomod github.com/golang/go/src go1.25.0 encoding/TextUnmarshaler#](v); m.IsValidscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/unmarshaler#IsValid. {
885 return m
886 }
887 // As the UnmarshalText function should be applied to the pointer of the
888 // type, we check that type to see if it implements the necessary
889 // method.
890 if _, m.IsValidscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/unmarshaler#IsValid. = reflectscip-go gomod github.com/golang/go/src go1.25.0 reflect/.TypeAssertscip-go gomod github.com/golang/go/src go1.25.0 reflect/TypeAssert().[encodingscip-go gomod github.com/golang/go/src go1.25.0 encoding/.TextUnmarshalerscip-go gomod github.com/golang/go/src go1.25.0 encoding/TextUnmarshaler#](reflectscip-go gomod github.com/golang/go/src go1.25.0 reflect/.Newscip-go gomod github.com/golang/go/src go1.25.0 reflect/New().(v.Typescip-go gomod github.com/golang/go/src go1.25.0 reflect/Value#Type().())); m.IsValidscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/unmarshaler#IsValid. {
891 m.IsPtrscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/unmarshaler#IsPtr. = true
892 return m
893 }
894
895 // if v is []T or *[]T create new T
896 t := v.Typescip-go gomod github.com/golang/go/src go1.25.0 reflect/Value#Type().()
897 if t.Kindscip-go gomod github.com/golang/go/src go1.25.0 reflect/Type#Kind().() == reflectscip-go gomod github.com/golang/go/src go1.25.0 reflect/.Ptrscip-go gomod github.com/golang/go/src go1.25.0 reflect/Ptr. {
898 t = t.Elemscip-go gomod github.com/golang/go/src go1.25.0 reflect/Type#Elem().()
899 }
900 if t.Kindscip-go gomod github.com/golang/go/src go1.25.0 reflect/Type#Kind().() == reflectscip-go gomod github.com/golang/go/src go1.25.0 reflect/.Slicescip-go gomod github.com/golang/go/src go1.25.0 reflect/Slice. {
901 // The slice type itself cannot implement encoding.TextUnmarshaler
902 // here: the value-level assert above already covered it. Check
903 // whether the elements do.
904 m.IsSliceElementscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/unmarshaler#IsSliceElement. = true
905 if t = t.Elemscip-go gomod github.com/golang/go/src go1.25.0 reflect/Type#Elem().(); t.Kindscip-go gomod github.com/golang/go/src go1.25.0 reflect/Type#Kind().() == reflectscip-go gomod github.com/golang/go/src go1.25.0 reflect/.Ptrscip-go gomod github.com/golang/go/src go1.25.0 reflect/Ptr. {
906 t = reflectscip-go gomod github.com/golang/go/src go1.25.0 reflect/.PointerToscip-go gomod github.com/golang/go/src go1.25.0 reflect/PointerTo().(t.Elemscip-go gomod github.com/golang/go/src go1.25.0 reflect/Type#Elem().())
907 m.IsSliceElementPtrscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/unmarshaler#IsSliceElementPtr. = true
908 _, m.IsValidscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/unmarshaler#IsValid. = reflectscip-go gomod github.com/golang/go/src go1.25.0 reflect/.TypeAssertscip-go gomod github.com/golang/go/src go1.25.0 reflect/TypeAssert().[encodingscip-go gomod github.com/golang/go/src go1.25.0 encoding/.TextUnmarshalerscip-go gomod github.com/golang/go/src go1.25.0 encoding/TextUnmarshaler#](reflectscip-go gomod github.com/golang/go/src go1.25.0 reflect/.Zeroscip-go gomod github.com/golang/go/src go1.25.0 reflect/Zero().(t))
909 return m
910 }
911 }
912
913 _, m.IsValidscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/unmarshaler#IsValid. = reflectscip-go gomod github.com/golang/go/src go1.25.0 reflect/.TypeAssertscip-go gomod github.com/golang/go/src go1.25.0 reflect/TypeAssert().[encodingscip-go gomod github.com/golang/go/src go1.25.0 encoding/.TextUnmarshalerscip-go gomod github.com/golang/go/src go1.25.0 encoding/TextUnmarshaler#](reflectscip-go gomod github.com/golang/go/src go1.25.0 reflect/.Newscip-go gomod github.com/golang/go/src go1.25.0 reflect/New().(t))
914 return m
915 }
916
917 // TextUnmarshaler helpers ----------------------------------------------------
918 // unmarshaler describes how a type relates to encoding.TextUnmarshaler.
919 // It carries type-level facts only; the decoder binds instances to live
920 // values at the point of use.
921 type unmarshalerscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/unmarshaler# struct {
922 // IsValid indicates whether the resolved type indicated by the other
923 // flags implements the encoding.TextUnmarshaler interface.
924 IsValidscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/unmarshaler#IsValid. bool
925 // IsPtr indicates that the resolved type is the pointer of the original
926 // type.
927 IsPtrscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/unmarshaler#IsPtr. bool
928 // IsSliceElement indicates that the resolved type is a slice element of
929 // the original type.
930 IsSliceElementscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/unmarshaler#IsSliceElement. bool
931 // IsSliceElementPtr indicates that the resolved type is a pointer to a
932 // slice element of the original type.
933 IsSliceElementPtrscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/unmarshaler#IsSliceElementPtr. bool
934 }
935
936 // Errors ---------------------------------------------------------------------
937
938 // ConversionError stores information about a failed conversion.
939 type ConversionErrorscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/ConversionError# struct {
940 Keyscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/ConversionError#Key. string // key from the source map.
941 Typescip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/ConversionError#Type. reflectscip-go gomod github.com/golang/go/src go1.25.0 reflect/.Typescip-go gomod github.com/golang/go/src go1.25.0 reflect/Type# // expected type of elem
942 Indexscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/ConversionError#Index. int // index for multi-value fields; -1 for single-value fields.
943 Errscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/ConversionError#Err. error // low-level error (when it exists)
944 }
945
946 func (e ConversionErrorscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/ConversionError#) Errorscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/ConversionError#Error().() string {
947 var output string
948
949 if e.Indexscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/ConversionError#Index. < 0 {
950 output = fmtscip-go gomod github.com/golang/go/src go1.25.0 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.25.0 fmt/Sprintf().("schema: error converting value for %q", e.Keyscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/ConversionError#Key.)
951 } else {
952 output = fmtscip-go gomod github.com/golang/go/src go1.25.0 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.25.0 fmt/Sprintf().("schema: error converting value for index %d of %q",
953 e.Indexscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/ConversionError#Index., e.Keyscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/ConversionError#Key.)
954 }
955
956 if e.Errscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/ConversionError#Err. != nil {
957 output = fmtscip-go gomod github.com/golang/go/src go1.25.0 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.25.0 fmt/Sprintf().("%s. Details: %s", output, e.Errscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/ConversionError#Err.)
958 }
959
960 return output
961 }
962
963 // UnknownKeyError stores information about an unknown key in the source map.
964 type UnknownKeyErrorscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/UnknownKeyError# struct {
965 Keyscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/UnknownKeyError#Key. string // key from the source map.
966 }
967
968 func (e UnknownKeyErrorscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/UnknownKeyError#) Errorscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/UnknownKeyError#Error().() string {
969 return fmtscip-go gomod github.com/golang/go/src go1.25.0 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.25.0 fmt/Sprintf().("schema: invalid path %q", e.Keyscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/UnknownKeyError#Key.)
970 }
971
972 // EmptyFieldError stores information about an empty required field.
973 type EmptyFieldErrorscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/EmptyFieldError# struct {
974 Keyscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/EmptyFieldError#Key. string // required key in the source map.
975 }
976
977 func (e EmptyFieldErrorscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/EmptyFieldError#) Errorscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/EmptyFieldError#Error().() string {
978 return fmtscip-go gomod github.com/golang/go/src go1.25.0 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.25.0 fmt/Sprintf().("%v is empty", e.Keyscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/EmptyFieldError#Key.)
979 }
980
981 // MultiError stores multiple decoding errors.
982 //
983 // Borrowed from the App Engine SDK.
984 type MultiErrorscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/MultiError# map[string]error
985
986 func (e MultiErrorscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/MultiError#) Errorscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/MultiError#Error().() string {
987 s := ""
988 for _, err := range e {
989 s = err.Error()
990 break
991 }
992 switch len(e) {
993 case 0:
994 return "(0 errors)"
995 case 1:
996 return s
997 case 2:
998 return s + " (and 1 other error)"
999 }
1000 return fmtscip-go gomod github.com/golang/go/src go1.25.0 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.25.0 fmt/Sprintf().("%s (and %d other errors)", s, len(e)-1)
1001 }
1002
1003 func appendRequiredFieldscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/appendRequiredField().(m map[string][]fieldWithPrefixscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/fieldWithPrefix#, key string, field fieldWithPrefixscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/fieldWithPrefix#) map[string][]fieldWithPrefixscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/fieldWithPrefix# {
1004 if m == nil {
1005 m = make(map[string][]fieldWithPrefixscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/fieldWithPrefix#)
1006 }
1007 m[key] = append(m[key], field)
1008 return m
1009 }
1010
1011 func appendErrorscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/appendError().(m MultiErrorscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/MultiError#, key string, err error) MultiErrorscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/MultiError# {
1012 if err == nil {
1013 return m
1014 }
1015 if m == nil {
1016 m = make(MultiErrorscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/MultiError#)
1017 }
1018 if m[key] == nil {
1019 m[key] = err
1020 }
1021 return m
1022 }
1023
1024 func mergeErrorsscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/mergeErrors().(dst, src MultiErrorscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/MultiError#) MultiErrorscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/MultiError# {
1025 if len(src) == 0 {
1026 return dst
1027 }
1028 if dst == nil {
1029 dst = make(MultiErrorscip-go gomod github.com/gofiber/schema . `github.com/gofiber/schema`/MultiError#, len(src))
1030 }
1031 for key, err := range src {
1032 if dst[key] == nil {
1033 dst[key] = err
1034 }
1035 }
1036 return dst
1037 }