I have a json that is POSTed by a browser. It's a hash with
var id int64 = 123
and, say, three fields like so:
myJson := `{
"a":"{'x1':'apple','x2':'orange'}",
"b":"{'y1':345678,'y2':32456}",
"c":"['alpha@example1.com', 'beta@example2.com']"}`
It's then stored in Redis using redigo with command:
HMSET id:123 a "{'x1':'apple','x2':'orange'}" b "{'y1':345678,'y2':32456}" c "['alpha@example1.com', 'beta@example2.com']"
Now, I'd like to use a model like this in Go
type Model struct {
A string `json:"a"`
B string `json:"b"`
C string `json:"c"` // Unknown length of map at runtime
}
1. I call Redis with
v, _ := redis.Values(c.Do("HGETALL", "id:123"))
I see correctly stored values via redis-cli, but converting the v reply into the Model struct doesn't work:
var model Model
if err := redis.ScanStruct(v, &model); err != nil {
panic(err)
}
fmt.Printf("c %#v
", model.C) => empty []
I'd like to access individual k:v pairs like:
B.y2 = 32456
C[0] = "alpha@example1.com"
2. I'd also like to json.Marshal myJson back to the browser as combinations of {a}, {a,b}, {a,c}, {a,b,c}, etc. I'm not sure how to combine various a,b,c field combos into one to be Marshalled.
Any help would be appreciated.