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