Codebase list golang-github-go-playground-validator-v10 / 3e196d4
saving some bytes uint8 vs int joeybloggs 7 years ago
4 changed file(s) with 29 addition(s) and 25 deletion(s). Raw diff Collapse all Expand all
152152 ctag = new(cTag)
153153 }
154154
155 cs.fields[i] = &cField{idx: i, name: fld.Name, altName: customName, cTags: ctag, namesEqual: fld.Name == customName}
155 cs.fields[i] = &cField{
156 idx: i,
157 name: fld.Name,
158 altName: customName,
159 cTags: ctag,
160 namesEqual: fld.Name == customName,
161 }
156162 }
157163
158164 v.structCache.Set(typ, cs)
131131 actualTag string
132132 ns string
133133 structNs string
134 fieldLen int
135 structfieldLen int
136 // field string
137 // structField string
138 value interface{}
139 param string
140 kind reflect.Kind
141 typ reflect.Type
134 fieldLen uint8
135 structfieldLen uint8
136 value interface{}
137 param string
138 kind reflect.Kind
139 typ reflect.Type
142140 }
143141
144142 // Tag returns the validation tag that failed.
168166 // fields actual name.
169167 func (fe *fieldError) Field() string {
170168 // return fe.field
171 return fe.ns[len(fe.ns)-fe.fieldLen:]
169 return fe.ns[len(fe.ns)-int(fe.fieldLen):]
172170 }
173171
174172 // returns the fields actual name from the struct, when able to determine.
175173 func (fe *fieldError) StructField() string {
176174 // return fe.structField
177 return fe.structNs[len(fe.structNs)-fe.structfieldLen:]
175 return fe.structNs[len(fe.structNs)-int(fe.structfieldLen):]
178176 }
179177
180178 // Value returns the actual fields value in case needed for creating the error
120120 actualTag: tag,
121121 ns: v.str1,
122122 structNs: v.str2,
123 fieldLen: len(fieldName),
124 structfieldLen: len(structFieldName),
123 fieldLen: uint8(len(fieldName)),
124 structfieldLen: uint8(len(structFieldName)),
125125 param: param,
126126 kind: kind,
127127 },
135135 actualTag: tag,
136136 ns: v.str1,
137137 structNs: v.str2,
138 fieldLen: len(fieldName),
139 structfieldLen: len(structFieldName),
138 fieldLen: uint8(len(fieldName)),
139 structfieldLen: uint8(len(structFieldName)),
140140 value: fv.Interface(),
141141 param: param,
142142 kind: kind,
116116 actualTag: ct.tag,
117117 ns: v.str1,
118118 structNs: v.str2,
119 fieldLen: len(cf.altName),
120 structfieldLen: len(cf.name),
119 fieldLen: uint8(len(cf.altName)),
120 structfieldLen: uint8(len(cf.name)),
121121 param: ct.param,
122122 kind: kind,
123123 },
132132 actualTag: ct.tag,
133133 ns: v.str1,
134134 structNs: v.str2,
135 fieldLen: len(cf.altName),
136 structfieldLen: len(cf.name),
135 fieldLen: uint8(len(cf.altName)),
136 structfieldLen: uint8(len(cf.name)),
137137 value: current.Interface(),
138138 param: ct.param,
139139 kind: kind,
326326 actualTag: ct.actualAliasTag,
327327 ns: v.str1,
328328 structNs: v.str2,
329 fieldLen: len(cf.altName),
330 structfieldLen: len(cf.name),
329 fieldLen: uint8(len(cf.altName)),
330 structfieldLen: uint8(len(cf.name)),
331331 value: current.Interface(),
332332 param: ct.param,
333333 kind: kind,
345345 actualTag: tVal,
346346 ns: v.str1,
347347 structNs: v.str2,
348 fieldLen: len(cf.altName),
349 structfieldLen: len(cf.name),
348 fieldLen: uint8(len(cf.altName)),
349 structfieldLen: uint8(len(cf.name)),
350350 value: current.Interface(),
351351 param: ct.param,
352352 kind: kind,
384384 actualTag: ct.tag,
385385 ns: v.str1,
386386 structNs: v.str2,
387 fieldLen: len(cf.altName),
388 structfieldLen: len(cf.name),
387 fieldLen: uint8(len(cf.altName)),
388 structfieldLen: uint8(len(cf.name)),
389389 value: current.Interface(),
390390 param: ct.param,
391391 kind: kind,