mirror of
https://github.com/go-gitea/gitea
synced 2024-11-18 16:14:26 +00:00
9fe4437bda
* Use vendored go-swagger * vendor go-swagger * revert un wanteed change * remove un-needed GO111MODULE * Update Makefile Co-Authored-By: techknowlogick <matti@mdranta.net>
42 lines
992 B
Go
Vendored
42 lines
992 B
Go
Vendored
package pretty
|
|
|
|
import (
|
|
"reflect"
|
|
)
|
|
|
|
func nonzero(v reflect.Value) bool {
|
|
switch v.Kind() {
|
|
case reflect.Bool:
|
|
return v.Bool()
|
|
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
|
|
return v.Int() != 0
|
|
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr:
|
|
return v.Uint() != 0
|
|
case reflect.Float32, reflect.Float64:
|
|
return v.Float() != 0
|
|
case reflect.Complex64, reflect.Complex128:
|
|
return v.Complex() != complex(0, 0)
|
|
case reflect.String:
|
|
return v.String() != ""
|
|
case reflect.Struct:
|
|
for i := 0; i < v.NumField(); i++ {
|
|
if nonzero(getField(v, i)) {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
case reflect.Array:
|
|
for i := 0; i < v.Len(); i++ {
|
|
if nonzero(v.Index(i)) {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
case reflect.Map, reflect.Interface, reflect.Slice, reflect.Ptr, reflect.Chan, reflect.Func:
|
|
return !v.IsNil()
|
|
case reflect.UnsafePointer:
|
|
return v.Pointer() != 0
|
|
}
|
|
return true
|
|
}
|