Gorilla maintainers have decided to shutter the doors to the project and archive the gorilla repositories. The maintainers are signaling that there will no future development on the projects, and are encouraging the community to make and maintain forks of the gorillia repositories. If a critical issue were to arise in one of the gorilla projects, a zero day or other bug, it is very unlikely that the fix for said issue will make it to the github.
golang.org/x/exp/slog is a new experimental package implementing a structured logger. Originating from this proposal it aims to get a structured logging library into the stdlib.
If you’re not familiar with structured logging. It is, generally, the superior way to do logging. The idea is just to add some structure to the log lines in the form of key value pairs. Typical structure is usually either JSON format, or simply separated by a space.
Maybe you’ve heard someone say something like;
“Gopath is deprecated, use go modules”.
While what they mean to say is true, that is developing in gopath mode is deprecated. When interpreted literally this statement is not true. And very likely confuses new comers to go. Lets peel back a layer of the onion and understand exactly what it is we mean to say.
The action of developing inside of Gopath and not using modules is deprecated.
In go Dependency Injection is a slightly different way to pass arguments to your function.
It’s not a ‘hack’ or dangerous. It’s not cargo cult programming. It’s not complex. It can be done without a framework. You don’t have to use it. But it will make your life easier. Injection # The pinnacle example for dependency injection is when writing http handler functions using net/http.
In go a function that handles http requests looks like this:
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 to help manage the life cycle of complex systems. We see it often in Go as its considered good practice, is part of the well vetted standard library, and is extremely useful.
In go we have context.Context which is an interface like 1
type Context interface { Deadline() (deadline time.
In languages that have first class functions we can define closures that lexically capture values in the scope that they are defined in.
package main import "fmt" func main() { b := true closure := func() error { err := fmt.Errorf("something bad happened!!") if b { return err } return nil } b = false err := closure() fmt.Printf("%v\n", err) } In this example we lexically capture b in our closure.
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.