mirror of
https://github.com/gin-gonic/gin.git
synced 2026-06-23 18:13:47 +08:00
Merge 3db7409fa5cbd47064a5bb7dd3efee50c2bcd4e7 into 2e4d4f38962a6f15ae496d59b294f307eef95429
This commit is contained in:
commit
9e5184e0fc
@ -51,7 +51,7 @@ func (v *defaultValidator) ValidateStruct(obj any) error {
|
||||
|
||||
value := reflect.ValueOf(obj)
|
||||
switch value.Kind() {
|
||||
case reflect.Ptr:
|
||||
case reflect.Pointer:
|
||||
if value.Elem().Kind() != reflect.Struct {
|
||||
return v.ValidateStruct(value.Elem().Interface())
|
||||
}
|
||||
|
||||
@ -13,7 +13,7 @@ import (
|
||||
func BenchmarkSliceValidationError(b *testing.B) {
|
||||
const size int = 100
|
||||
e := make(SliceValidationError, size)
|
||||
for j := 0; j < size; j++ {
|
||||
for j := range size {
|
||||
e[j] = errors.New(strconv.Itoa(j))
|
||||
}
|
||||
|
||||
|
||||
@ -47,7 +47,7 @@ func mapFormByTag(ptr any, form map[string][]string, tag string) error {
|
||||
// Check if ptr is a map
|
||||
ptrVal := reflect.ValueOf(ptr)
|
||||
var pointed any
|
||||
if ptrVal.Kind() == reflect.Ptr {
|
||||
if ptrVal.Kind() == reflect.Pointer {
|
||||
ptrVal = ptrVal.Elem()
|
||||
pointed = ptrVal.Interface()
|
||||
}
|
||||
@ -88,7 +88,7 @@ func mapping(value reflect.Value, field reflect.StructField, setter setter, tag
|
||||
|
||||
vKind := value.Kind()
|
||||
|
||||
if vKind == reflect.Ptr {
|
||||
if vKind == reflect.Pointer {
|
||||
var isNew bool
|
||||
vPtr := value
|
||||
if value.IsNil() {
|
||||
@ -376,7 +376,7 @@ func setWithProperType(val string, value reflect.Value, field reflect.StructFiel
|
||||
return json.API.Unmarshal(bytesconv.StringToBytes(val), value.Addr().Interface())
|
||||
case reflect.Map:
|
||||
return json.API.Unmarshal(bytesconv.StringToBytes(val), value.Addr().Interface())
|
||||
case reflect.Ptr:
|
||||
case reflect.Pointer:
|
||||
if !value.Elem().IsValid() {
|
||||
value.Set(reflect.New(value.Type().Elem()))
|
||||
}
|
||||
|
||||
@ -34,7 +34,7 @@ func (r *multipartRequest) TrySet(value reflect.Value, field reflect.StructField
|
||||
|
||||
func setByMultipartFormFile(value reflect.Value, field reflect.StructField, files []*multipart.FileHeader) (isSet bool, err error) {
|
||||
switch value.Kind() {
|
||||
case reflect.Ptr:
|
||||
case reflect.Pointer:
|
||||
switch value.Interface().(type) {
|
||||
case *multipart.FileHeader:
|
||||
value.Set(reflect.ValueOf(files[0]))
|
||||
|
||||
@ -35,7 +35,7 @@ func decodePlain(data []byte, obj any) error {
|
||||
|
||||
v := reflect.ValueOf(obj)
|
||||
|
||||
for v.Kind() == reflect.Ptr {
|
||||
for v.Kind() == reflect.Pointer {
|
||||
if v.IsNil() {
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -155,7 +155,7 @@ func readNthLine(file string, n int) (string, error) {
|
||||
defer f.Close()
|
||||
|
||||
scanner := bufio.NewScanner(f)
|
||||
for i := 0; i < n; i++ {
|
||||
for range n {
|
||||
if !scanner.Scan() {
|
||||
return "", nil
|
||||
}
|
||||
|
||||
@ -41,7 +41,7 @@ func waitForServerReady(url string, maxAttempts int) error {
|
||||
Timeout: 100 * time.Millisecond,
|
||||
}
|
||||
|
||||
for i := 0; i < maxAttempts; i++ {
|
||||
for i := range maxAttempts {
|
||||
resp, err := client.Get(url)
|
||||
if err == nil {
|
||||
resp.Body.Close()
|
||||
|
||||
2
utils.go
2
utils.go
@ -28,7 +28,7 @@ const localhostIPv6 = "::1"
|
||||
// Bind is a helper function for given interface object and returns a Gin middleware.
|
||||
func Bind(val any) HandlerFunc {
|
||||
value := reflect.ValueOf(val)
|
||||
if value.Kind() == reflect.Ptr {
|
||||
if value.Kind() == reflect.Pointer {
|
||||
panic(`Bind struct can not be a pointer. Example:
|
||||
Use: gin.Bind(Struct{}) instead of gin.Bind(&Struct{})
|
||||
`)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user