think that there are two struct, they have different fields, hope that there has a function merge(a,b interface{}) interface{}, input param are any two struct, they may have same-type, or have different-type. output param is a struct that composed the two input struct, example type A sturct{Name string}, type B struct{Age int}, a,b :=A{"xxx"},B{10} called c:= merge(a,b), c is interface{}, and
import "github.com/google/go-querystring/query", v, _ := query.Values(opt) fmt.Print(v.Encode()) // will output: "name=xxx&age=10" 在 2019年8月24日星期六 UTC+8下午1:25:24,burak serdar写道: > > On Fri, Aug 23, 2019 at 11:11 PM Lee Rick <blade...@gmail.com > <javascript:>> wrote: > > > > it's not my need, hope other methods > > What is your need? What are the types of the variables d1, d2, d3 in > your example? > > > > > 在 2019年8月24日星期六 UTC+8上午11:43:32,burak serdar写道: > >> > >> On Fri, Aug 23, 2019 at 9:25 PM Lee Rick <blade...@gmail.com> wrote: > >> > > >> > i want to do > >> > type A struct{ Name string} > >> > type B struct{Age int} > >> > type C struct{Address string} > >> > > >> > a, b, c := A{}, B{},C{} > >> > have a function > >> > d1 := merge(a,b) //d1 like struct{Name string, Age int} > >> > d2 := merge(a,c) //d2 like struct{Name string, Address string} > >> > d3 := merge(b,c) //d3 like struct{Age int, Address string} > >> > >> You cannot have a function that merges two structs and returns a new > >> one, but you can have structs that are compositions of other structs. > >> > >> type AB struct { > >> A > >> B > >> } > >> > >> Struct AB is a struct containing both A and B. You can access the > >> members of A and B as though they're members of AB. > >> > >> ab:=AB{} > >> ab.Name="a" > >> ab.Age=1 > >> > >> This is also valid: > >> > >> ab.A.Name="a" > >> ab.B.Age=1 > >> > >> Initialization has to be explicit though: > >> > >> ab:=AB{A:A{Name:"name"}, B:B{Age:1}} > >> > >> > >> > >> > >> > > >> > > >> > how to realize merge function? anyone can give me a demo > >> > > >> > -- > >> > You received this message because you are subscribed to the Google > Groups "golang-nuts" group. > >> > To unsubscribe from this group and stop receiving emails from it, > send an email to golan...@googlegroups.com. > >> > To view this discussion on the web visit > https://groups.google.com/d/msgid/golang-nuts/9d0f4159-146b-4d5b-91c0-8846445a84d4%40googlegroups.com. > > > > > > -- > > You received this message because you are subscribed to the Google > Groups "golang-nuts" group. > > To unsubscribe from this group and stop receiving emails from it, send > an email to golan...@googlegroups.com <javascript:>. > > To view this discussion on the web visit > https://groups.google.com/d/msgid/golang-nuts/f7e61c2d-1aef-4160-b525-7d9c2488f9e1%40googlegroups.com. > > > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/eede40bf-a7e9-41d9-9a79-ea70989ff8f1%40googlegroups.com.