Source File
map.go
Belonging Package
github.com/imdario/mergo
package mergo
import (
)
func ( string, func(rune) rune) string {
if == "" {
return
}
, := utf8.DecodeRuneInString()
return string(()) + [:]
}
func ( reflect.StructField) bool {
, := utf8.DecodeRuneInString(.Name)
return >= 'A' && <= 'Z'
}
[] = &visit{, , }
}
:= reflect.Value{}
switch .Kind() {
case reflect.Map:
:= .Interface().(map[string]interface{})
for , := 0, .NumField(); < ; ++ {
:= .Type()
:= .Field()
if !isExported() {
continue
}
:= .Name
= changeInitialCase(, unicode.ToLower)
if , := []; ! || (isEmptyValue(reflect.ValueOf()) || ) {
[] = .Field().Interface()
}
}
case reflect.Ptr:
if .IsNil() {
:= reflect.New(.Type().Elem())
.Set()
}
= .Elem()
fallthrough
case reflect.Struct:
:= .Interface().(map[string]interface{})
for := range {
.overwriteWithEmptyValue = true
:= []
:= changeInitialCase(, unicode.ToUpper)
:= .FieldByName()
if != reflect.Ptr && .CanAddr() {
:= .Addr()
= reflect.ValueOf()
= reflect.Ptr
}
}
if !.IsValid() {
continue
}
if == {
if _, = deepMerge(, , , +1, ); != nil {
return
}
} else if == reflect.Interface && .Kind() == reflect.Interface {
if _, = deepMerge(, , , +1, ); != nil {
return
}
} else if == reflect.Map {
if = (, , , +1, ); != nil {
return
}
} else {
return fmt.Errorf("type mismatch on %s field: found %v, expected %v", , , )
}
}
}
return
}
if .Kind() == .Kind() {
, := deepMerge(, , make(map[uintptr]*visit), 0, )
return
}
switch .Kind() {
case reflect.Struct:
if .Kind() != reflect.Map {
return ErrExpectedMapAsDestination
}
case reflect.Map:
if .Kind() != reflect.Struct {
return ErrExpectedStructAsDestination
}
default:
return ErrNotSupported
}
return deepMap(, , make(map[uintptr]*visit), 0, )
![]() |
The pages are generated with Golds v0.3.2-preview. (GOOS=darwin GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds. |