golang interface{} 类型转换

package main

import (
    "fmt"
    "strconv"
)

var articleId interface{}
func main() {
        articleId = 12.0
        switch articleId.(type) {
        case string:
            fmt.Println("string ***", articleId)
        case float64:
            fmt.Println("float64****", strconv.FormatFloat(articleId.(float64), 'f', -1, 64))
        case []byte:
        fmt.Println("[]byte****", string(articleId.([]byte)))
    }
}

    原文作者:nwwyt2
    原文地址: https://www.jianshu.com/p/e037c9d68219
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞