下面是代码示例:
func GetValue(c echo.Context) error {
//other implementation details
value, err := service.GetValue()
if err != nil {
return c.JSON(http.StatusBadRequest, errorresponse.Error(4003, err))
}
//if I set same value here, it works as expected
//value.Value = []int8{48, 48, 48, 54, 54, 49, 56, 54, 32, 32, 32, 32, 32, 32, 32}
return c.JSON(http.StatusOK, value)
}
//this is type service.GetValue() returns
type ValueGetResponse struct {
Value interface{}
ValueType string
}
如果我使用来自方法的值,API 会给我一个类似于波纹管的响应。它把它转换成某种我不知道的字符串。当我检查属性时,说,它是一个as类型。此外,VSCode 调试器也会批准它。service.GetValue()value.Valuereflect.TypeOf(value.Value)[]int8
请求中使用的对象:
回应:
{
"Value": "MDAwNjYxODYgICAgICAg",
"ValueType": "[]uint8"
}
如果我手动设置期望值,它按预期工作,我不明白为什么第一个不是。
value.Value = []int8{48, 48, 48, 54, 54, 49, 56, 54, 32, 32, 32, 32, 32, 32, 32}
请求中使用的对象:

回应:
{
"Value": [
48,
48,
48,
54,
54,
49,
56,
54,
32,
32,
32,
32,
32,
32,
32,
32
],
"ValueType": "[]uint8"
}
回首忆惘然
相关分类