Building on the approach outlined in Write Your Own json.Unmarshal , I want to introduce a versatile data model for Go to handle serialized data and a straightforward way to unmarshal it into Go types. Recap of the Problem The core challenge was mapping different data sources — such as http.Request.PathValue or url.Values — into a Go struct. Ideally, we wanted something as simple and intuitive as…
I had a recent situation where I needed to populate an existing struct with values, similar to the way json.Unmarshal works. These values would come from various sources, like URL query parameters, form data, path variables, or something along those lines. To give an example, I needed to map a URL like /newStudent?name=Albert&age=16&city=Zurich onto a Golang struct like this: type Student struct {…