【Go】interface{} 转string

func Get(f string,value interface{}) interface{}{
	temp := fmt.Sprint(value)
	switch f.Type {
	case "string":
		return temp
	case "bool":
		b,err := strconv.ParseBool(temp)
		if err!=nil{
			return "Bool类型输入错误"
		}
		return b
	case "int":
		b,err := strconv.ParseInt(temp,10,64)
		if err!=nil{
			return "Number类型输入错误"
		}
		return b
	default:
		return "请输入正确的数据类型"
	}
}
posted @ 2023-02-09 16:39  gtea  阅读(379)  评论(0编辑  收藏  举报