From 5054057acdcbf805eb24fc01521728c9bcc7bdd4 Mon Sep 17 00:00:00 2001 From: Tom Bevan <tom.bevan@r3labs.io> Date: Mon, 12 Jul 2021 17:21:31 +0100 Subject: [PATCH 1/2] assign an empty type when patch value is nil --- change_value.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/change_value.go b/change_value.go index 7d7ca08..4d721e9 100644 --- a/change_value.go +++ b/change_value.go @@ -123,7 +123,12 @@ func (c *ChangeValue) Set(value reflect.Value, convertCompatibleTypes bool) { } c.target.Set(value.Convert(c.target.Type())) } else { - c.target.Set(value) + if value.IsValid() { + c.target.Set(value) + } else { + t := c.target.Elem() + t.Set(reflect.Zero(t.Type())) + } } c.SetFlag(FlagApplied) } From 5f0fcde00ed846c3c1fe0b31335682743d9729a3 Mon Sep 17 00:00:00 2001 From: Tom Bevan <tom.bevan@r3labs.io> Date: Mon, 12 Jul 2021 17:30:20 +0100 Subject: [PATCH 2/2] fix travis-ci badges --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 5d0a549..ef16bc5 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Diff [![PkgGoDev](https://pkg.go.dev/badge/github.com/r3labs/diff)](https://pkg.go.dev/github.com/r3labs/diff) [![Go Report Card](https://goreportcard.com/badge/github.com/r3labs/diff)](https://goreportcard.com/report/github.com/r3labs/diff) [![Build Status](https://travis-ci.org/r3labs/diff.svg?branch=master)](https://travis-ci.org/r3labs/diff) +# Diff [![PkgGoDev](https://pkg.go.dev/badge/github.com/r3labs/diff)](https://pkg.go.dev/github.com/r3labs/diff) [![Go Report Card](https://goreportcard.com/badge/github.com/r3labs/diff)](https://goreportcard.com/report/github.com/r3labs/diff) [![Build Status](https://travis-ci.com/r3labs/diff.svg?branch=master)](https://travis-ci.com/r3labs/diff) A library for diffing golang structures and values.