Test Driven Development With Golang on OSX

How to do Test Driven Development with Go on OSX You are looking to start using TDD, but you want a simple tool setup to automate running your tests and giving you the red green display. I have been trying out different setups for programming Go with TDD on OSX, and I am going to show you one that is easy to setup. This post will cover the setup you need to code in one screen and have your tests automatically run and output in another screen.

Go sql examples

Go sql examples using sqlx Assume you have two models a type Business and a type Widget in a one to many relationship. I want to demonstrate two ways that you can load the widgets into a business object using sqlx. I am using postgresql. package models import ( "database/sql" "github.com/jmoiron/sqlx" "github.com/pkg/errors" "time" ) type Business struct { Id int64 `db:"id" json:"id"` Name string `db:"name" json:"name"` Website sql.NullString `db:"website" json:"

Golang YAML to map

How to convert a YAML file to a map[string]string in Go Use go-yamlconfigfile project to convert simple yaml config files to maps in Go. When you want to store secrets for your project, you should never keep them in source control. There have been too many documented cases of secrets being leaked because of this. If you are using public version control like github, people can simple scan through your history to find things you may have accidentally released to the public internet.

How to process xml with invalid utf-8 bytes in Go including ISO 8859 1 encodings

I recently had to process a large number of xml files that were not UTF-8 encoded. They also happened to include characters that were outside the valid ASCII range. I did not really want to keep these invalid characters, and this solution will work for that use case. If you do need to keep non-ascii characters, this simple solution will not work for you. The trick to making this work is to create a wrapper around the io.

Go Closures as Struct Members

How to store closures at runtime inside struct members in the Go programming language. I will also show you how you can change the closure stored as a member inside of your struct at runtime. I have used Perl for many years, and you can easily pass around closures and dynamically redefine classes at run time. You can even create entire classes at run time, I have done this, and it makes some really interesting patterns.

How to compile libvips on OSX from source for image processing

Here are the steps needed to compile libvips from source. If you try to install it from homebrew, you will most likely run into a number of errors regarding the dependency gtk-doc. This will frustrate you, and you might abandon the effort. I will show you how to install the latest stable libvips without having to install gtk-doc I normally do not like to use dependencies like this in my Go project, but the performance of image processing needs to be really good as this type of computing tends to use a ton of resources on a server.

How to ignore vendor directory in git for Go projects

You accidentally added your vendor directory to git in your Go project. Now when you run git status you see all these modified files under the vendor directory. Here is a quick command you can use to ignore these changes First change to your project directory then run this command git status | perl -ne ‘/(vendor.+go)/ && system “git update-index –assume-unchanged $1\n”;’ This will take each file mentioned in the status that is in your vendor directory and execute a git command against it to

Golang Vendoring How to add vendoring to an existing Go project

How to add Vendoring to an existing Go Project to manage your dependencies In this post I want to discuss how you can add vendoring for your dependencies to an existing Go project that does not currently have a vendor directory. I am working on a new version of Best Food Near Me. The original version used a version of Go that did not have vendoring support, but it has since been upgraded.

Using Go and Perl in your Makefile.PL as part of your build process

Perl and Golang I want to show you quickly how you can integrate your Go programs into your Perl module process. That is, if you have a go executable program that you want to distribute with your Perl module and you also want to build the go executable as part of your Perl module build process, this is how you can do it. I am assuming you have Go installed, and I am also assuming you are using ExtUtils::MakeMaker for your Perl module.

Consul Service Discovery and leader election

Elect a leader with Consul for your service So I started testing out a service discovery platform called Consul by the company Hashicorp. The system uses the raft consensus protocol, and you may run into issues with leader election when you try to restart each server node. I did, and before you start spending hours googling around, I am going to tell you what I did to elect a leader in my cluster.