Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to overwrite Struct Pointer Field with nil? #149

Closed
loeffel-io opened this issue Jun 9, 2020 · 3 comments
Closed

How to overwrite Struct Pointer Field with nil? #149

loeffel-io opened this issue Jun 9, 2020 · 3 comments

Comments

@loeffel-io
Copy link

loeffel-io commented Jun 9, 2020

Following code DO NOT overwrite user with nil

Tested with all kind of options: mergo.WithOverride, mergo.WithOverwriteWithEmptyValue, mergo.WithOverrideEmptySlice, mergo.WithTypeCheck

log.Printf("%+v", token) // before
if err = mergo.Merge(token, &go_saas_model.Token{
	User:    nil,
	TeamId:  &teamId,
	Team:    nil,
	RWMutex: new(sync.RWMutex),
}, mergo.WithOverride, mergo.WithOverwriteWithEmptyValue, mergo.WithOverrideEmptySlice, mergo.WithTypeCheck); err != nil {
	c.AbortWithStatusJSON(h.StatusInternalServerError, http.Response(err, nil))
	return
}
log.Printf("%+v", token) // after
2020/06/09 11:46:44 &{Model:{Id:0 CreatedAt:0001-01-01 00:00:00 +0000 UTC UpdatedAt:0001-01-01 00:00:00 +0000 UTC DeletedAt:<nil>} Token:0xc0003cb300 Note:0xc0003cb310 UserId:0xc0002c66e8 User:0xc000502a20 TeamId:<nil> Team:<nil> RWMutex:<nil>}
2020/06/09 11:46:44 &{Model:{Id:0 CreatedAt:0001-01-01 00:00:00 +0000 UTC UpdatedAt:0001-01-01 00:00:00 +0000 UTC DeletedAt:<nil>} Token:0xc0003cb300 Note:0xc0003cb310 UserId:0xc0002c66e8 User:0xc000502a20 TeamId:0xc000129018 Team:<nil> RWMutex:0xc000142f00}
@loeffel-io
Copy link
Author

Looks like #123

@loeffel-io
Copy link
Author

Looks like this is not fixed in v0.3.10-0.20200608072158-7527e3cdd3f4

@darccio
Copy link
Owner

darccio commented Jul 16, 2020

Fixed in branch issue-149. Some tests are failing there because master is broken right now. I'll check what is happening (it isn't from the changes I did to fix it).

By the other hand, please avoid in the future comments like "Same trash as mergo". Not only for me, but also for the maintainers of conjungo. I can't speak for them but I create and share my code in my free time. Mergo isn't perfect - actually I'm planning a new clean room implementation - but nobody deserves to be trashed like this.

Also, please provide isolated and simplified examples when reporting errors. It took me some time to find your project, read your code and understand what are you trying to achieve.

darccio added a commit that referenced this issue Jul 16, 2020
darccio added a commit that referenced this issue Jul 17, 2020
@darccio darccio closed this as completed Jul 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants