Skip to content
Discussion options

You must be logged in to vote

@sourabh-khot65 I'm afraid your code doesn't reproduce the issue: https://go.dev/play/p/U5rnLXo5YlI

package main

import (
	"fmt"

	"dario.cat/mergo"
)

type Candidate struct {
	FirstName *string
	LastName  *string
	Skills    *string
}

func ptr(s string) *string {
	return &s
}

func main() {
	dest := &Candidate{
		FirstName: ptr("John"),
		LastName:  ptr("Doe"),
		Skills:    nil, // Empty destination field
	}

	src := &Candidate{
		LastName: ptr("Smith"),
		Skills:   ptr("Go"), // Source has a value
	}

	// Merge without override
	err := mergo.Merge(dest, src)
	if err != nil {
		fmt.Println("Error:", err)
		return
	}

	fmt.Printf("FirstName: %q; LastName: %q; Skills: %q\n", *dest.FirstName

Replies: 3 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by darccio
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants