interface{}类型的值中,默认解析为float64类型。
1 2 3 4 5 6 7 |
func(c *gin.Context) { // c.Get()返回的值 类型是interface{} userId,_ := c.Get("UserId") // userId是interface{}类型,interface{}只能转为float64 // 使用int()把float64转为int,最后使用strconv.Itoa()把int转为string id := strconv.Itoa(int(userId.(float64))) } |