mirror of
https://github.com/charlienet/go-mixed.git
synced 2025-07-18 08:32:40 +08:00
isZero
This commit is contained in:
@ -53,6 +53,17 @@ func (s *Struct) Values() []any {
|
||||
return values
|
||||
}
|
||||
|
||||
func (s *Struct) IsZero() bool {
|
||||
for _, fi := range s.fields {
|
||||
source := s.value.FieldByName(fi.name)
|
||||
if !source.IsZero() {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
func (s *Struct) ToMap() map[string]any {
|
||||
m := make(map[string]any, len(s.fields))
|
||||
for _, fi := range s.fields {
|
||||
@ -112,6 +123,16 @@ func Map2Struct(o map[string]any, dst any) {
|
||||
|
||||
}
|
||||
|
||||
func IsZero(o any) bool {
|
||||
v := reflect.ValueOf(o)
|
||||
if v.IsZero() {
|
||||
return true
|
||||
}
|
||||
|
||||
s := New(o)
|
||||
return s.IsZero()
|
||||
}
|
||||
|
||||
func Struct2Map(o any, opts ...optionFunc) map[string]any {
|
||||
return New(o, opts...).ToMap()
|
||||
}
|
||||
|
Reference in New Issue
Block a user