Go的cannot convert t(type interface {}) to type string: need type assertion 使用fmt.Sprintf转换
生活随笔
收集整理的這篇文章主要介紹了
Go的cannot convert t(type interface {}) to type string: need type assertion 使用fmt.Sprintf转换
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
問題1
assertionn. 斷言,聲明;主張,要求;堅(jiān)持;認(rèn)定 在使用interface表示任何類型時(shí),如果要將interface轉(zhuǎn)為某一類型,直接強(qiáng)制轉(zhuǎn)換是不行的,例如: var t interface{} = "abc" s := string(t) cannot convert t(type interface {}) to type string: need type assertion方法
c.Ctx.WriteString(fmt.Sprintf("%v", count))使用 fmt.Sprintf("%v",value)即可解決問題2
方法2
link := fmt.Sprint("%s",conn.RemoteAddr())onlineConns[link] = conn?
總結(jié)
以上是生活随笔為你收集整理的Go的cannot convert t(type interface {}) to type string: need type assertion 使用fmt.Sprintf转换的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 信用卡密码忘记了怎么办 可以通过这2种
- 下一篇: 利好!电影院终于要开门了,手中的影视股或