Introduction to VPS and Web Technology Development

golang interface转字符串

自由vps golang
func Strval(value interface{}) string { var key string  if value == nil { return key
   } switch value.(type) { case float64:
      ft := value.(float64)
      key = strconv.FormatFloat(ft, 'f', -1, 64) case float32:
      ft := value.(float32)
      key = strconv.FormatFloat(float64(ft), 'f', -1, 64) case int:
      it := value.(int)
      key = strconv.Itoa(it) case uint:
      it := value.(uint)
      key = strconv.Itoa(int(it)) case int8:
      it := value.(int8)
      key = strconv.Itoa(int(it)) case uint8:
      it := value.(uint8)
      key = strconv.Itoa(int(it)) case int16:
      it := value.(int16)
      key = strconv.Itoa(int(it)) case uint16:
      it := value.(uint16)
      key = strconv.Itoa(int(it)) case int32:
      it := value.(int32)
      key = strconv.Itoa(int(it)) case uint32:
      it := value.(uint32)
      key = strconv.Itoa(int(it)) case int64:
      it := value.(int64)
      key = strconv.FormatInt(it, 10) case uint64:
      it := value.(uint64)
      key = strconv.FormatUint(it, 10) case string:
      key = value.(string) case []byte:
      key = string(value.([]byte)) default:
      newValue, _ := json.Marshal(value)
      key = string(newValue)
   } return key
}
使用chatGPT寻求答案
标签: 暂无标签

免责声明:

本站提供的资源,都来自网络,版权争议与本站无关,所有内容及软件的文章仅限用于学习和研究目的。不得将上述内容用于商业或者非法用途,否则,一切后果请用户自负,我们不保证内容的长久可用性,通过使用本站内容随之而来的风险与本站无关,您必须在下载后的24个小时之内,从您的电脑/手机中彻底删除上述内容。如果您喜欢该程序,请支持正版软件,购买注册,得到更好的正版服务。侵删请致信E-mail:master@freevpsweb.com

同类推荐
评论列表