4 ms·
I think that was more of an example. There are lots of ways to fail gracefully when you don't have the data you want in the dict.
by claudiawerner 5y ago
I think that was more of an example. There are lots of ways to fail gracefully when you don't have the data you want in the dict.
- tptacek 5y agoRight, which is why json.Unmarshal returns an error, and why map lookups return an extra `ok` value in Go.
- tgsovlerkhgsel 5y agoIt would be a lot more than 4 lines in Go though. Either the struct definition, or a lot of `if !ok return error`. Especially once the nesting gets deeper.
- tptacek 5y agoI'm pretty sure it would just be an `if err != nil {http.Error(w, err.Error(), 501); return }`.
- tgsovlerkhgsel 5y agoone of these for each nesting level.