Copyright 2014 Dario Castañé. All rights reserved. Copyright 2009 The Go Authors. All rights reserved. Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
Based on src/pkg/reflect/deepequal.go from official golang's stdlib.

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'
}
Traverses recursively both values, assigning src's fields values to dst. The map argument tracks comparisons that have already been seen, which allows short circuiting on recursive types.
func (,  reflect.Value,  map[uintptr]*visit,  int,  *Config) ( error) {
	 := .Overwrite
	if .CanAddr() {
		 := .UnsafeAddr()
		 := 17 * 
		 := []
		 := .Type()
		for  := ;  != nil;  = .next {
			if .ptr ==  && .typ ==  {
				return nil
			}
Remember, remember...
		[] = &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()
We discard it because the field doesn't exist.
				continue
			}
			 := reflect.ValueOf()
			 := .Kind()
			 := .Kind()
			if  == reflect.Ptr &&  != reflect.Ptr {
				 = .Elem()
				 = reflect.TypeOf(.Interface()).Kind()
Can this work? I guess it can't.
				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
}
Map sets fields' values in dst from src. src can be a map with string keys or a struct. dst must be the opposite: if src is a map, dst must be a valid pointer to struct. If src is a struct, dst must be map[string]interface{}. It won't merge unexported (private) fields and will do recursively any exported field. If dst is a map, keys will be src fields' names in lower camel case. Missing key in src that doesn't match a field in dst will be skipped. This doesn't apply if dst is a map. This is separated method from Merge because it is cleaner and it keeps sane semantics: merging equal types, mapping different (restricted) types.
func (,  interface{},  ...func(*Config)) error {
	return _map(, , ...)
}
MapWithOverwrite will do the same as Map except that non-empty dst attributes will be overridden by non-empty src attribute values. Deprecated: Use Map(…) with WithOverride
func (,  interface{},  ...func(*Config)) error {
	return _map(, , append(, WithOverride)...)
}

func (,  interface{},  ...func(*Config)) error {
	var (
		,  reflect.Value
		        error
	)
	 := &Config{}

	for ,  := range  {
		()
	}

	if , ,  = resolveValues(, );  != nil {
		return 
To be friction-less, we redirect equal-type arguments to deepMerge. Only because arguments can be anything.
	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, )