Is there a way to copy only the not null fields?
Example:
package main
import (
"fmt"
"github.com/gotidy/copy"
)
type Player struct {
Firstname string
Username *string
UserDetail *UserDetail
}
type PlayerInput struct {
Firstname *string
Username *string
UserDetail *UserDetail
}
type UserDetail struct {
Email *string
}
func main() {
inputFirstname := "Bob"
input := PlayerInput{
Firstname: &inputFirstname,
}
outputUsername := "BobTheBob"
output := Player{
Username: &outputUsername,
}
c := copy.New()
c.Get(&output, &input).Copy(&output, &input)
fmt.Printf("%#v \n", output)
}
I get:
main.Player{Firstname:"Bob", Username:(*string)(nil), UserDetail:(*main.UserDetail)(nil)}
I would:
main.Player{Firstname:"Bob", Username:"BobTheBob", UserDetail:(*main.UserDetail)(nil)}
Is this possible?
Is there a way to copy only the not null fields?
Example:
I get:
I would:
Is this possible?