This question already has an answer here:
I have used:
https://mholt.github.io/json-to-go/
to convert
{
"id": 5533,
"action": "/api/v1/private/subscribe",
"arguments": {
"instrument": ["BTC-19DEC14"],
"event": ["order_book", "trade", "user_order"]
}
}
into
type AutoGenerated struct {
ID int `json:"id"`
Action string `json:"action"`
Arguments struct {
Instrument []string `json:"instrument"`
Event []string `json:"event"`
} `json:"arguments"`
}
I have then tried to use this in Go code as follows:
package main
import (
"flag"
"os"
)
var addr = flag.String("addr", "www.deribit.com", "http service address")
func main() {
type AutoGenerated struct {
ID int `json:"id"`
Action string `json:"action"`
Arguments struct {
Instrument []string `json:"instrument"`
Event []string `json:"event"`
} `json:"arguments"`
}
json := &AutoGenerated{
ID: 42,
Action: "/api/v1/public/getorderbook",
Arguments: struct {
Instrument: ["BTC-19DEC14"],
Event: ["order_book", "trade", "user_order"],
},
}
}
I'm getting an error with Arguments
ie my struct within a struct.
How do I convert my JSON to a variable that I can use within go?
</div>