go – Golang WriteHeaderAndJson returns wrong result-ThrowExceptions

Exception or error:

I got the following code running in azure which returns wrong output when calling the api from Azure cloudshell, but returns correct result when I run it locally on my Ubuntu terminal.

type S struct {
Properties SProperties `json:"properties"`
}

type SProperties struct {
    Available bool `json:"available"`
}

result = S{
    Properties: SProperties{
        Available:            true,
    },
}

ContainerServiceRessource.SyncOperationContext.Response.WriteHeaderAndJson(200, result, "application/json; charset=UTF-8")

Expected output:

{
"properties": {
"available": true
}
}

actual output:
{\n \"properties\": {\n \"available\": true\n }\n }

I don’t know what is going on.
I got 3 apis in the same format just returning different availabilities. two of them are not working well like stated above and the last one is working as expected.

Any help is appreciated.
Thanks!

How to solve:

Leave a Reply

Your email address will not be published. Required fields are marked *