Skip to content

Commit

Permalink
Revert "remove logrus to avoid golang/go#26208"
Browse files Browse the repository at this point in the history
This reverts commit ed7b45e.
  • Loading branch information
birdayz committed Nov 27, 2018
1 parent ed7b45e commit 4eb7246
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 9 deletions.
17 changes: 11 additions & 6 deletions _example/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,13 @@ import (
"reflect"

"github.com/InVisionApp/conjungo"
log "github.com/sirupsen/logrus"
)

func init() {
log.SetLevel(log.InfoLevel)
}

func main() {
fmt.Println("Simple map merge")
SimpleMap()
Expand Down Expand Up @@ -51,7 +56,7 @@ func SimpleMap() {

err := conjungo.Merge(&targetMap, sourceMap, nil)
if err != nil {
fmt.Println(err)
log.Error(err)
}

marshalIndentPrint(targetMap)
Expand Down Expand Up @@ -81,7 +86,7 @@ func SimpleStruct() {

err := conjungo.Merge(&targetStruct, sourceStruct, nil)
if err != nil {
fmt.Println(err)
log.Error(err)
}

marshalIndentPrint(targetStruct)
Expand Down Expand Up @@ -126,7 +131,7 @@ func CustomMerge() {

err := conjungo.Merge(&targetMap, sourceMap, opts)
if err != nil {
fmt.Println(err)
log.Error(err)
}

marshalIndentPrint(targetMap)
Expand Down Expand Up @@ -167,7 +172,7 @@ func CustomStructMerge() {

err := conjungo.Merge(&target, source, opts)
if err != nil {
fmt.Println(err)
log.Error(err)
}

marshalIndentPrint(target)
Expand All @@ -190,7 +195,7 @@ func NoOverwrite() {
opts.Overwrite = false
err := conjungo.Merge(&targetMap, sourceMap, opts)
if err != nil {
fmt.Println(err)
log.Error(err)
}

marshalIndentPrint(targetMap)
Expand Down Expand Up @@ -251,7 +256,7 @@ func FromJSON() {

err := conjungo.Merge(&targetJSON, sourceJSON, opts)
if err != nil {
fmt.Println(err)
log.Error(err)
}

fmt.Println(targetJSON)
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ module github.com/birdayz/conjungo
require (
github.com/onsi/ginkgo v1.7.0
github.com/onsi/gomega v1.4.3
github.com/sirupsen/logrus v1.2.0
)
14 changes: 14 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,18 +1,32 @@
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I=
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/golang/protobuf v1.2.0 h1:P3YflyNX/ehuJFLhxviNdFxQPkGK5cDcApsge1SqnvM=
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI=
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
github.com/konsorten/go-windows-terminal-sequences v1.0.1 h1:mweAR1A6xJ3oS2pRaGiHgQ4OO8tzTaLawm8vnODuwDk=
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/ginkgo v1.7.0 h1:WSHQ+IS43OoUrWtD1/bbclrwK8TTH5hzp+umCiuxHgs=
github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/gomega v1.4.3 h1:RE1xgDvH7imwFD45h+u2SgIfERHlS2yNG4DObb5BSKU=
github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/sirupsen/logrus v1.2.0 h1:juTguoYk5qI21pwyTXY3B3Y5cOTH3ZUyZCg1v/mihuo=
github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
golang.org/x/crypto v0.0.0-20180904163835-0709b304e793 h1:u+LnwYTOOW7Ukr/fppxEb1Nwz0AtPflrblfvUudpo+I=
golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd h1:nTDtHvHSdCn1m6ITfMRqtOd/9+7a3s8RBNOZ3eYZzJA=
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f h1:wMNYb4v58l5UBM7MYRLPG6ZhfOqbKu7X5eyFl8ZhKvA=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e h1:o3PsSEY8E4eXWkXrIP9YJALUkVZqzHJT5DOasTyn8Vs=
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
Expand Down
5 changes: 5 additions & 0 deletions merge_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,16 @@ package conjungo
import (
"testing"

"github.com/sirupsen/logrus"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)

func TestMergeSuite(t *testing.T) {
// reduce the noise when testing
logrus.SetLevel(logrus.FatalLevel)

RegisterFailHandler(Fail)
RunSpecs(t, "Merge Suite")
}
8 changes: 5 additions & 3 deletions mfunc.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package conjungo
import (
"fmt"
"reflect"

"github.com/sirupsen/logrus"
)

// A MergeFunc defines how two items are merged together. It should accept a reflect.Value
Expand Down Expand Up @@ -97,7 +99,7 @@ func mergeMap(t, s reflect.Value, o *Options) (v reflect.Value, err error) {
}()

for _, k := range keys {
fmt.Printf("MERGE T<>S '%s' :: %v <> %v\n", k, t.MapIndex(k), s.MapIndex(k))
logrus.Debugf("MERGE T<>S '%s' :: %v <> %v", k, t.MapIndex(k), s.MapIndex(k))
val, err := merge(t.MapIndex(k), s.MapIndex(k), o)
if err != nil {
return reflect.Value{}, fmt.Errorf("key '%s': %v", k, err)
Expand Down Expand Up @@ -137,7 +139,7 @@ func mergeStruct(t, s reflect.Value, o *Options) (reflect.Value, error) {

for i := 0; i < valS.NumField(); i++ {
fieldT := newT.Field(i)
fmt.Printf("merging struct field %s\n", fieldT)
logrus.Debugf("merging struct field %s", fieldT)

// field is addressable because it's created above. So this means it is unexported.
if !fieldT.CanSet() {
Expand All @@ -158,7 +160,7 @@ func mergeStruct(t, s reflect.Value, o *Options) (reflect.Value, error) {
}

if !merged.IsValid() {
fmt.Printf("merged value is invalid for field %s. Falling back to default merge: %v <> %v\n",
logrus.Warnf("merged value is invalid for field %s. Falling back to default merge: %v <> %v",
newT.Type().Field(i).Name, valT.Field(i), valS.Field(i))

// if merge returned an invalid value, fallback to a default merge for the field
Expand Down

0 comments on commit 4eb7246

Please sign in to comment.