News for hackers. Stuff that matters.
Re:Map[string]interface{} in Go: a user's manual by claudiawerner on Monday July 26, 2021 @06:22PM (#27966209)
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.
Re:Map[string]interface{} in Go: a user's manual by tptacek on Monday July 26, 2021 @06:28PM (#27966254)
Right, which is why json.Unmarshal returns an error, and why map lookups return an extra `ok` value in Go.
Re:Map[string]interface{} in Go: a user's manual by tgsovlerkhgsel on Monday July 26, 2021 @07:03PM (#27966569)
It 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.
Re:Map[string]interface{} in Go: a user's manual by tptacek on Monday July 26, 2021 @07:29PM (#27966797)
I'm pretty sure it would just be an `if err != nil {http.Error(w, err.Error(), 501); return }`.
Re:Map[string]interface{} in Go: a user's manual by tgsovlerkhgsel on Monday July 26, 2021 @11:19PM (#27968251)
one of these for each nesting level.