Giter VIP home page Giter VIP logo

conjungo's People

Contributors

bstanley0811 avatar caledhwa avatar dselans avatar talpert avatar wbbradley avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

conjungo's Issues

Creates duplicates in nested struct slices

Behavior

When merging a struct with slices of structs, Conjungo will create duplicate items in the slice.

Expected Behavior

When merging a slice of structs in a struct I expect it to not create duplicates in the array, but skip the structs that are equal.

Test Case

package main

import (
	"testing"

	"github.com/InVisionApp/conjungo"
	"github.com/stretchr/testify/assert"
)

type TestStruct struct {
	Val       string
	Resources []NestedStruct
}

type NestedStruct struct {
	Key string
	Val string
}

func TestNestedStructMerge(t *testing.T) {
	s1 := TestStruct{
		Val: "a struct",
		Resources: []NestedStruct{
			NestedStruct{
				Key: "k1",
				Val: "v1",
			},
		},
	}

	s2 := TestStruct{
		Val: "a struct",
		Resources: []NestedStruct{
			NestedStruct{
				Key: "k1",
				Val: "v1",
			},
		},
	}

	// Confirming that the Resources are equal according to the == operator
	assert.Equal(t, s2.Resources, s1.Resources)

	// Confirming that the main structs themselves are equal according to the == operator
	assert.Equal(t, s2, s1)

	// Asserting no errors
	assert.Nil(t, conjungo.Merge(&s2, s1, conjungo.NewOptions()))

	// I expect there to be only 1 item in the target struct's array
	assert.Len(t, s2.Resources, 1)
}

Yields different results if a structs field is a pointer vs. value

https://play.golang.org/p/mgcKU7YcxX1

That also results to the custom type merge function not beeing called.

I debugged it until https://github.com/InVisionApp/conjungo/blob/master/mfunc.go#L60. Where v.Type() is Ptr, and it can't find a default merge function for that kind, since there's none.

So it continues and uses https://github.com/InVisionApp/conjungo/blob/master/mfunc.go#L80 which just replaces the whole tree without deep merging further

merge strings correctly(only non "" values)

strings cant be nil, this they will always be overwritten in conjungo.
a possible fix is by checking if the value is the same as reflect.Zero(v.Type()) instead of just nil

Same trash as mergo

This will set the User field not to nil

opts := conjungo.NewOptions()
opts.Overwrite = true
if err = conjungo.Merge(token, &go_saas_model.Token{
	User:    nil,
	TeamId:  &teamId,
	Team:    nil,
	RWMutex: new(sync.RWMutex),
}, opts); err != nil {
	c.AbortWithStatusJSON(h.StatusInternalServerError, http.Response(err, nil))
	return
}

ref: darccio/mergo#149

Release

Can you do a github release, so that I can vendor a specific version and easily compare versions when new features are added?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.