Pages tagged "golang"
Golang Closures For Configuration
One common code smell is creating functions with a long list of parameters. Adding a new function usually starts out optimistically with a few inputs or known state that is needed. Over time you start adding more state and extending functionality of existing code and quickly it turns into something that is no longer maintainable or causes issues of other places in the codebase needed a larger list of dependencies and state to call these codepaths. Let’s look at one approach you can take with golang.
Golang Debug Bytes
Golang Printing Tabstopped Text into Aligned Columns
One of the strengths of Golang as a language is it has a pretty strong standard library of packages out of the box. Things like the httptest package and even the http package is strong enough that there are countless http servers open sourced built on top of it. One of the hidden convenient packages I’ve used is the tabwriter to help print out tabstopped text into aligned text.
Golang Testing time.Now
Testing time objects can be a pain. Some languages offer some helpful libraries that can help like VCR in Ruby. Other tools to help are mocking libraries to where you can mock and stub out the time calls to what you want. In golang there is another way to help and that is using dependency injection to help make testing easier.
Golang Documenting Package Examples
Go has been gaining a lot of popularity recently. With a lot of the success stories centered on the performance gains switching from other languages. For me a lot of the smaller features, that shows an attention to detail, which makes it enjoyable to code in.
Golang Timed Function Wrapper
Wrote this quick and probably dirty wrapper for timing functions in Go.
TimedReturn
returns an interface{}
in case a return value is needed
from whatever you are wrapping.
Golang Package Version Flag
So you’ve built your first service using Go and have it deployed out into your production environment. With cross compiling built into Go it’s easy and almost trivial to build a new binary of your code and deploy updates.
Golang Current File Path
I recently needed to get the current file absolute path from a go file. You first need to get the runtime package which is a part of Go