func solveEqualityMergeConflict(conflicts map[string]MergeConflict) (map[string]MergeSolution, error) {
	solution := make(map[string]MergeSolution, len(conflicts))
	unsolvableConflicts := map[string]MergeConflict{}
	for key, value := range conflicts {
		if value.Left.Equals(value.Right) {
			solution[key] = MergeSolution{Side: LeftSide, Solution: value.Left, Discarded: value.Right}
		} else {
			unsolvableConflicts[key] = value
		}
	}
	if len(unsolvableConflicts) != 0 {
		return solution, MergeConflictError{Err: "Could not solve all conflicts", Conflicts: unsolvableConflicts}
	}
	return solution, nil
}
solveEqualityMergeConflict solves conflicts that arise, if the same Model entry exists
on both sides. For other conflicts it returns a mergeConflictError asking the caller
to handle it.
package merger
import (
	"fmt"
	"reflect"
	"time"
)
type MergeConflictSolver func(map[string]MergeConflict) (map[string]MergeSolution, error)
func AutoResolveConflicts(conflicts map[string]MergeConflict, resolverName string) (map[string]MergeSolution, error) {
	resolver, err := parseResolver(resolverName)
	if err != nil {
		return nil, err
	}
	if resolver == nil {
		return nil, nil
	}
	return resolver(conflicts)
}
func SolveConflictByChoosingLeft(conflicts map[string]MergeConflict) (map[string]MergeSolution, error) {
	return solveConflictByChoosingSide(conflicts, LeftSide)
}
func SolveConflictByChoosingRight(conflicts map[string]MergeConflict) (map[string]MergeSolution, error) {
	return solveConflictByChoosingSide(conflicts, RightSide)
}
func parseResolver(name string) (MergeConflictSolver, error) {
	if name == "" {
		return nil, nil
	}
	switch name {
	case "chooseLeft":
		return SolveConflictByChoosingLeft, nil
	case "chooseRight":
		return SolveConflictByChoosingRight, nil
	case "chooseNewest":
		return SolveConflictByChoosingNewest, nil
	}
	return nil, fmt.Errorf("%s is not a valid conflict resolver. Can be 'chooseNewest', 'chooseLeft', or 'chooseRight'", name)
}
func SolveConflictByChoosingNewest(conflicts map[string]MergeConflict) (map[string]MergeSolution, error) {
	solution := make(map[string]MergeSolution, len(conflicts))
	for key, value := range conflicts {
		leftModified := reflect.ValueOf(value.Left).Elem().FieldByName("LastModified")
		rightModified := reflect.ValueOf(value.Right).Elem().FieldByName("LastModified")
		if !leftModified.IsValid() || !rightModified.IsValid() {
			return nil, fmt.Errorf("Not able to use SolveConflictByChoosingNewest, as %T has no 'LastModified' field", value.Left)
		}
		leftDate, err := time.Parse("2006-01-02T15:04:05-07:00", leftModified.String())
		if err != nil {
			return nil, err
		}
		rightDate, err := time.Parse("2006-01-02T15:04:05-07:00", rightModified.String())
		if err != nil {
			return nil, err
		}
		if leftDate.After(rightDate) {
			solution[key] = MergeSolution{Side: LeftSide, Solution: value.Left, Discarded: value.Right}
		} else {
			solution[key] = MergeSolution{Side: RightSide, Solution: value.Right, Discarded: value.Left}
		}
	}
	return solution, nil
}
func solveConflictByChoosingSide(conflicts map[string]MergeConflict, side MergeSide) (map[string]MergeSolution, error) {
	solution := make(map[string]MergeSolution, len(conflicts))
	for key, value := range conflicts {
		if side == LeftSide {
			solution[key] = MergeSolution{Side: LeftSide, Solution: value.Left, Discarded: value.Right}
		} else {
			solution[key] = MergeSolution{Side: RightSide, Solution: value.Right, Discarded: value.Left}
		}
	}
	return solution, nil
}