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

Boolean not empty #166

Closed
vasilevkirill opened this issue Oct 12, 2020 · 2 comments
Closed

Boolean not empty #166

vasilevkirill opened this issue Oct 12, 2020 · 2 comments

Comments

@vasilevkirill
Copy link

vasilevkirill commented Oct 12, 2020

hi im use this code

type Interface struct {
	Name            string
	Enabled         bool
	AutoNegotiation bool
	Speed           int
	FullDuplex      bool
	FlowControlTx   bool
	FlowControlRx   bool
}

newInterface := Interface{
     Name:    "SDWAN-CLIENT-878",
     Enabled: false,
}
oldInterface := Interface{
    Name:            "OriginalName",
    Enabled:         true,
    AutoNegotiation: true,
    Speed:           1000,
    FullDuplex:      true,
    FlowControlTx:   true,
    FlowControlRx:   false,
}
if err := mergo.Merge(&newInterface, oldInterface); err != nil {
    log.Panic(err)
}
log.Printf("%+v",newInterface)

Log Printing
{Name:SDWAN-CLIENT-878 Enabled:true AutoNegotiation:true Speed:1000 FullDuplex:true FlowControlTx:true FlowControlRx:false}

I am waiting Field Enabled equal false same as in the variable newInterface

it's possible in mergo?

thanks.

@xscode-auto-reply
Copy link

Thanks for opening a new issue. The team has been notified and will review it as soon as possible.
For urgent issues and priority support, visit https://xscode.com/imdario/mergo

@yyong37
Copy link

yyong37 commented Dec 9, 2020

issue131_test maybe help you.

GGabriele added a commit to Kong/mergo that referenced this issue Feb 1, 2022
Mergo handles merges with zero-value fields as follows:

	1. dst: true       src: false      ->     dst: true
	2. dst: nil        src: false      ->     dst: false
	3. dst: nil	   src: true	   ->	  dst: true
	4. dst: false	   src: true 	   ->	  dst: true

In some cases (darccio#166) it may be desirable
to change this default behaviour using a custom Transformer, for example
to not overwrite 'dst' when it's already set to 'false' (or '0' etc).
Unfortunately, in such cases (when dst holds a zero-value) no Transformers can
be applied due to the way these are gated (darccio#166).

Here we are changing how transformers are gated by using the isReflectNil function
insted of isEmptyValue.

Note that:
- this change doesn't affect the default behaviour of mergo, as it only affects
  how transformers are gated
- since custom transformers need to match data types in order to execute,
  this shouldn't affect any existing transformers either
@darccio darccio closed this as completed May 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants