1
0
mirror of https://github.com/charlienet/go-mixed.git synced 2025-07-18 08:32:40 +08:00
This commit is contained in:
2022-05-13 14:19:44 +08:00
parent 25e8c8c58b
commit d4d68dc263
5 changed files with 48 additions and 4 deletions

View File

@ -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()
}