Default values when unmarshal json in go


If we want to unmarshal a json into a struct, and we want to have default values if a value is absent in the json, the following code can be used: type LogEndpoint struct { MaxLogLevel int `json:"max_log_level"` } func (o *LogEndpoint) UnmarshalJSON(text []byte) error { type defaults LogEndpoint opts := defaults{ MaxLogLevel: 5, } if err := json.Unmarshal(text, &opts); err != nil { return err } *o = LogEndpoint(opts) return nil } The code provides a method called UnmarshalJSON that belongs to a struct called LogEndpoint.

Time management

time todo list

The last view days I had a lot of time to think about time management and todo lists. I had an accident during a ski mountaineering tour, and so I had to stay in the hospital. I am still there, but I am ok and happy to be still alive. The problem statement There are certain resolutions that we make, like: doing more sport, maybe twice a week spending more time with the family meet the friends relax as you can imagine the list can go on.

Learning go

edited on Feb 22, 2024

This entry contains great learning materials for go. Starting A Tour of Go: At the very beginning, you can start with A Tour of Go. This is a go tutorial that allows you to learn and run go code directly in your Browser. Also, the Tour can be downloaded to take it offline. golang-standards: For beginners, it’s not so clear how to structure a go repository. The following link gives a good introduction.

New Website


Welcome to the redesign of the freelenzer website. Everything is new, so content also gets renewed. Please stay tuned, and visit again. If you are searching for an old article, please email me.