-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
339 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
// Copyright GoFrame Author(https://goframe.org). All Rights Reserved. | ||
// | ||
// This Source Code Form is subject to the terms of the MIT License. | ||
// If a copy of the MIT was not distributed with this file, | ||
// You can obtain one at https://github.com/gogf/gf. | ||
|
||
package utils | ||
|
||
import ( | ||
"github.com/gogf/gf/internal/empty" | ||
"reflect" | ||
) | ||
|
||
// IsNil checks whether `value` is nil. | ||
func IsNil(value interface{}) bool { | ||
return value == nil | ||
} | ||
|
||
// IsEmpty checks whether `value` is empty. | ||
func IsEmpty(value interface{}) bool { | ||
return empty.IsEmpty(value) | ||
} | ||
|
||
// IsInt checks whether `value` is type of int. | ||
func IsInt(value interface{}) bool { | ||
switch value.(type) { | ||
case int, *int, int8, *int8, int16, *int16, int32, *int32, int64, *int64: | ||
return true | ||
} | ||
return false | ||
} | ||
|
||
// IsUint checks whether `value` is type of uint. | ||
func IsUint(value interface{}) bool { | ||
switch value.(type) { | ||
case uint, *uint, uint8, *uint8, uint16, *uint16, uint32, *uint32, uint64, *uint64: | ||
return true | ||
} | ||
return false | ||
} | ||
|
||
// IsFloat checks whether `value` is type of float. | ||
func IsFloat(value interface{}) bool { | ||
switch value.(type) { | ||
case float32, *float32, float64, *float64: | ||
return true | ||
} | ||
return false | ||
} | ||
|
||
// IsSlice checks whether `value` is type of slice. | ||
func IsSlice(value interface{}) bool { | ||
var ( | ||
reflectValue = reflect.ValueOf(value) | ||
reflectKind = reflectValue.Kind() | ||
) | ||
for reflectKind == reflect.Ptr { | ||
reflectValue = reflectValue.Elem() | ||
} | ||
switch reflectKind { | ||
case reflect.Slice, reflect.Array: | ||
return true | ||
} | ||
return false | ||
} | ||
|
||
// IsMap checks whether `value` is type of map. | ||
func IsMap(value interface{}) bool { | ||
var ( | ||
reflectValue = reflect.ValueOf(value) | ||
reflectKind = reflectValue.Kind() | ||
) | ||
for reflectKind == reflect.Ptr { | ||
reflectValue = reflectValue.Elem() | ||
} | ||
switch reflectKind { | ||
case reflect.Map: | ||
return true | ||
} | ||
return false | ||
} | ||
|
||
// IsStruct checks whether `value` is type of struct. | ||
func IsStruct(value interface{}) bool { | ||
var ( | ||
reflectValue = reflect.ValueOf(value) | ||
reflectKind = reflectValue.Kind() | ||
) | ||
for reflectKind == reflect.Ptr { | ||
reflectValue = reflectValue.Elem() | ||
reflectKind = reflectValue.Kind() | ||
} | ||
switch reflectKind { | ||
case reflect.Struct: | ||
return true | ||
} | ||
return false | ||
} |
Oops, something went wrong.