Since both json.Marshal and json.Unmarshal may return an error, it would be nice to extend those functions to functions that must complete, or panic. This is useful for declaring vars at the head of a file, or passing the result of json.MustMarshal to a function as an argument
For comparison, consider regexp.MustCompile where you may
// rest if your code
The text was updated successfully, but these errors were encountered:
Using consts was the solution that I was using before, though interpolating strings with varaibles can lead to code that is pretty ugly in my opinion. I could go back to using strings here, for example
I agree that these funcs would have a very limited usecase, but I would also think that it is a relatively simple implementation that is not backwards incompatible. It would panic presumable on programmer error, and save other tools from needing to add it to their projects
I can see how it can be useful in some niche cases, but writing your own helper function is just a handful of lines. Backwards compatibility and simplicity are not the only factors for adding API to the standard library - see https://golang.org/doc/faq#x_in_std.