This is the code example:
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
}
If I use the value which comes from service.GetValue()
method, the API gives me a response like bellow. It converts it to a some kind of string which I don't know. When I check the value.Value
property, the reflect.TypeOf(value.Value)
says, it is a []int8
as type. Also the VSCode debugger approves it.
THE OBJECT USED IN REQUEST:
THE RESPONSE:
{
"Value": "MDAwNjYxODYgICAgICAg",
"ValueType": "[]uint8"
}
If I set expected value manually, it works as expected and I do not understand why the first one is not.
value.Value = []int8{48, 48, 48, 54, 54, 49, 56, 54, 32, 32, 32, 32, 32, 32, 32}
THE OBJECT USED IN REQUEST:
THE RESPONSE:
{
"Value": [
48,
48,
48,
54,
54,
49,
56,
54,
32,
32,
32,
32,
32,
32,
32,
32
],
"ValueType": "[]uint8"
}