cannot convert data (type interface {}) to type string: need type assertion

前端 未结 4 734
予麋鹿
予麋鹿 2020-12-07 07:28

I am pretty new to go and I was playing with this notify package.

At first I had code that looked like this:

func doit(w http.ResponseWriter, r *http         


        
4条回答
  •  再見小時候
    2020-12-07 07:58

    As asked for by @ρяσѕρєя an explanation can be found at https://golang.org/pkg/fmt/#Sprint. Related explanations can be found at https://stackoverflow.com/a/44027953/12817546 and at https://stackoverflow.com/a/42302709/12817546. Here is @Yuanbo's answer in full.

    package main
    
    import "fmt"
    
    func main() {
        var data interface{} = 2
        str := fmt.Sprint(data)
        fmt.Println(str)
    }
    

提交回复
热议问题