go-superstruct

[library] uses reflection to merge structs
git clone https://hhvn.uk/go-superstruct
git clone git://hhvn.uk/go-superstruct
Log | Files | Refs | LICENSE

example_test.go (341B)


      1 package superstruct
      2 
      3 import (
      4 	_ "testing"
      5 	"fmt"
      6 )
      7 
      8 type first struct {
      9 	A string
     10 	C string
     11 }
     12 
     13 type second struct {
     14 	B string
     15 	C string
     16 }
     17 
     18 
     19 func Example() {
     20 	a := first{"a", "c"}
     21 	b := second{"b", "d"}
     22 	c, err := CreateAndCopy(a, b)
     23 	if err != nil {
     24 		return
     25 	}
     26 
     27 	fmt.Println(SortedStructString(c))
     28 	// Output:
     29 	// A: a
     30 	// B: b
     31 	// C: d
     32 }