Hitchhiker’s Guide To Context

If you’re new to Go you might have seen some functions like func Foo(ctx context.Context) error Context is a pattern frequently used in systems programming to help manage the life cycle of complex systems. We see often in Go as its considered good practice, is part of the standard library, and is extremely useful. In go we have context.Context which is an interface like 1 type Context interface { Deadline() (deadline time.
Read more →

struct-to-map

Occasionally in go we want convert our structured data into an unstructured format, such as a map[string]interface{} for struct like: type Foo struct { A Bar `json:"a"` B Bar `json:"b"` C Bar `json:"c"` D Bar `json:"d"` E Bar `json:"e"` F int `json:"f"` G uint `json:"g"` H string `json:"h"` } type Bar struct { Bar string `json:"bar"` } There are a couple ways we can convert it into a map. manually func base(foo Foo) map[string]interface{} { result := make(map[string]interface{}) result["A"] = foo.
Read more →