I have a struct like this:
package main
import (
"encoding/json"
"fmt"
)
type request struct {
Version string `json:"version"`
Operations map[string]operation `json:"operations"`
}
type operation struct {
Type string `json:"type"`
Width int `json:"width"`
Height int `json:"height"`
}
func main() {
jsonStr := "{\"version\": \"1.0\", \"operations\": {\"0\": {\"type\": \"type1\", \"width\": 100}, \"1\": {\"type\": \"type2\", \"height\": 200}}}"
req := request{
Version: "1.0",
}
err := json.Unmarshal([]byte(jsonStr), &req)
if err != nil {
fmt.Println(err.Error())
} else {
fmt.Println(req)
}
}
I can set Version = "1.0" as its default value, but how can I set default value to Width and Height?