在go语言中interface转string可以直接使用fmt提供的fmt函数,而转bool和int则是在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 "请输入正确的数据类型"
	}
}