I recently submitted a PR to an open source project, a CLI tool. I stumbled upon a few requests for the maintainer to add support of parsing an .env file while invoking the CLI.
I find this desire ridiculous. And there is no shortage of this desire in other projects.
Should every application parse a .env file for configuration? Obviously, no. We all ready have plenty of convenient ways of automatically setting env vars.
Hello! Been about 6 mo since I posted a blog, wanted to post some housekeeping updates.
Thankfully a maintainer has been found for all the gorilla libraries. As they make changes to gorilla I will encourage others to continue using the main repo so that I do not have to any longer maintain my fork and maybe eventually remove my fork completely. I plan on revamping my site including moving away from hugo completely, maybe a custom solution for me.
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:
Runtime errors are a bit different in Go compared to other languages. Go lacks the familiar error handling like try/catch. In Go errors are values like any other kind of type in go. Because of this we often see signatures that are like
func DoSomething() error or func FetchSomething() (results, error)
And our functions tend to be composed of a lot of
if err != nil { return err } We call this “bubbling up” the error, as the error is bubbled up the call stack until we reach a point where we can make a decision about the error.
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.
don’t use service desks as a means of collaboration inside of an organization.
Service, or Help Desks are a system that have been in use since the beginning of the internet. We often see companies that deliver software to large user bases have a help desk that is ran by a support team. This brings the company numerous benefits including:
Cost effective support for confused consumers. Better understanding of the software to its consumers.