I followed a thread in here and came up with this
var b Button
queryErr := connection.QueryRow("SELECT id_printer, name, has_children FROM button WHERE id_parent IS NULL;").Scan(&b.ID, &b.Name, &b.Children)
if queryErr != nil {
response, err := json.MarshalIndent(b, "", " ")
fmt.Fprint(w, string(response))
if err != nil {
log.Println("Error on jsonmarshalindent Starter")
}
} else {
log.Println("Error on queryErr starter")
log.Println(queryErr)
fmt.Fprint(w, "Error getting starter button")
}
it has 2 problems:
- It breaks on b.Children
- I don't know how to make it dynamically. for instance, the query returns 3 rows, but it depends on the company's client, it can be 3 or any number.
the struct is
type Starter struct {
Buttons []Button `json:buttons`
}
type Button struct {
ID int `json:id`
Name string `json:name`
Children bool `json:children`
}
Can someone shed some light in this please?
if queryErr != nil... but the block beneath that is for when the error is actuallynil. Perhaps fixing that will print the underlying error for you to diagnose. We will need to know what "it breaks" means. Surely theres a panic or something that is being hidden by that incorrect conditional.