草庐IT

multiple-interface-implem

全部标签

types - 调用 Go 函数,它接受接口(interface) A 的 slice 和结构 B 的 slice (B 实现 A)

我有以下类型:typeStatementinterface{Say()string}typeQuotestruct{quotestring}func(pQuote)Say()string{returnp.quote}funcReplay(conversation[]Statement){for_,statement:=rangeconversation{fmt.Println(statement.Say())}}我想我已经很好地理解了为什么接受[]Statement类型参数的函数不能用[]Quote调用;即使Quote实现了Statement,[]Quote也没有实现[]Stateme

types - 调用 Go 函数,它接受接口(interface) A 的 slice 和结构 B 的 slice (B 实现 A)

我有以下类型:typeStatementinterface{Say()string}typeQuotestruct{quotestring}func(pQuote)Say()string{returnp.quote}funcReplay(conversation[]Statement){for_,statement:=rangeconversation{fmt.Println(statement.Say())}}我想我已经很好地理解了为什么接受[]Statement类型参数的函数不能用[]Quote调用;即使Quote实现了Statement,[]Quote也没有实现[]Stateme

go - 在 Go 中扩展接口(interface)

相当新。我正在尝试修改此goscribe服务器实现:https://github.com/samuel/go-thrift/blob/master/examples/scribe_server/main.go我想将channel传递给Log()函数,这样我就可以将抄写数据传递给单独的go例程,但我不确定如何修改scribe/thrift.go将日志接口(interface)扩展为Log(messages[]*scribe.LogEntry,countschanstring)(或者是否需要这样做,以及是否有某种方法可以在不扰乱原始库的情况下扩展接口(interface))。

go - 在 Go 中扩展接口(interface)

相当新。我正在尝试修改此goscribe服务器实现:https://github.com/samuel/go-thrift/blob/master/examples/scribe_server/main.go我想将channel传递给Log()函数,这样我就可以将抄写数据传递给单独的go例程,但我不确定如何修改scribe/thrift.go将日志接口(interface)扩展为Log(messages[]*scribe.LogEntry,countschanstring)(或者是否需要这样做,以及是否有某种方法可以在不扰乱原始库的情况下扩展接口(interface))。

pointers - 在 Go 中,类型和指向类型的指针都可以实现接口(interface)吗?

例如在下面的例子中:typeFoodinterface{Eat()bool}typevegetable_sstruct{//somedata}typeVegetable*vegetable_stypeSaltstruct{//somedata}func(pVegetable)Eat()bool{//somecode}func(pSalt)Eat()bool{//somecode}Vegetable和Salt是否都满足Food,即使一个是指针而另一个直接是结构? 最佳答案 答案很容易通过compilingthecode得到:prog.

pointers - 在 Go 中,类型和指向类型的指针都可以实现接口(interface)吗?

例如在下面的例子中:typeFoodinterface{Eat()bool}typevegetable_sstruct{//somedata}typeVegetable*vegetable_stypeSaltstruct{//somedata}func(pVegetable)Eat()bool{//somecode}func(pSalt)Eat()bool{//somecode}Vegetable和Salt是否都满足Food,即使一个是指针而另一个直接是结构? 最佳答案 答案很容易通过compilingthecode得到:prog.

mysql - Golang 加入数组接口(interface)

我尝试创建批量插入。我使用gormgithub.com/jinzhu/gormimport("fmt"dB"github.com/edwinlab/api/repositories")funcUpdate()error{tx:=dB.GetWriteDB().Begin()sqlStr:="INSERTINTOcity(code,name)VALUES(?,?),(?,?)"vals:=[]interface{}{}vals=append(vals,"XX1","Jakarta")vals=append(vals,"XX2","Bandung")tx.Exec(sqlStr,vals)

mysql - Golang 加入数组接口(interface)

我尝试创建批量插入。我使用gormgithub.com/jinzhu/gormimport("fmt"dB"github.com/edwinlab/api/repositories")funcUpdate()error{tx:=dB.GetWriteDB().Begin()sqlStr:="INSERTINTOcity(code,name)VALUES(?,?),(?,?)"vals:=[]interface{}{}vals=append(vals,"XX1","Jakarta")vals=append(vals,"XX2","Bandung")tx.Exec(sqlStr,vals)

go - 如何为接口(interface){}设置任何值

我有以下代码:packagemainimport("fmt")typePointstruct{x,yint}funcdecode(valueinterface{}){fmt.Println(value)//->&{0,0}//Thisissimplifiedexample,insteadofvalueofPointtype,there//canbevalueofanytype.value=&Point{10,10}}funcmain(){varp=new(Point)decode(p)fmt.Printf("x=%d,y=%d",p.x,p.y)//->x=0,y=0,expected

go - 如何为接口(interface){}设置任何值

我有以下代码:packagemainimport("fmt")typePointstruct{x,yint}funcdecode(valueinterface{}){fmt.Println(value)//->&{0,0}//Thisissimplifiedexample,insteadofvalueofPointtype,there//canbevalueofanytype.value=&Point{10,10}}funcmain(){varp=new(Point)decode(p)fmt.Printf("x=%d,y=%d",p.x,p.y)//->x=0,y=0,expected