#development #golang #tools

James is your butler and helps you to create, build, debug, test and run your Go projects.

When you often create new apps using Go, it quickly becomes annoying when you realize all the steps it takes to configure the basics. You need to manually create the source files, version info requires more steps to be injected into the executable, using Visual Studio Code requires you to manually setup the tasks you want to run…

Using the go-james tool, you can automate and streamline this process. The tool will take care of initializing your project, running your project, debugging it, building it and running the tests.


In version 1.5.0, the followings things are changed/updated/fixed:

  • We have added support for creating Docker images.
  • Integration of the staticcheck analyzer
  • Default VSCode settings when creating a new project

You can find a list of fixed issues in the milestone.

Docker Support

When you craete a new project or run the init command on an existing project, we now add a .dockerignore file and a sample Dockerfile. The Dockerfile is a multi-stage docker build you can use as a starting point to customize:

 1FROM golang:alpine AS mod-download
 2
 3RUN apk update && apk add git && rm -rf /var/cache/apk/*
 4RUN GO111MODULE=on go get -u github.com/pieterclaerhout/go-james/cmd/go-james
 5
 6RUN mkdir -p /app
 7
 8ADD go.mod /app
 9ADD go.sum /app
10
11WORKDIR /app
12
13
14RUN go mod download
15
16FROM mod-download AS builder
17
18ADD . /app
19WORKDIR /app
20
21RUN CGO_ENABLED=0 go-james build -v
22
23
24FROM scratch
25
26COPY --from=builder "/app/build/go-example" /
27
28ENTRYPOINT ["/go-example"]

Firstly, you'll see that we are using the latest Go version running on Alpine Linux. This works great and is a pretty small image to use.

We use go-james (obviously) to do the actual building. As this is a multi-stage build, we first download all the needed modules and cache them for later. The next time you run the build and if the dependencies are not changed, they will not be redownloaded.

The final binary runs using the scratch image which is the smallest Docker image you can create. To build the image, you just need to run:

1go-james docker-image

Staticcheck

In version 1.5.0, we also integrated the staticcheck tool. For those not familiar with it, staticcheck is static analysis toolset for the Go programming language. It comes with a large number of checks, integrates with various Go build systems and offers enough customizability to fit into your workflows. It can analyze your source code and offer loads of tips, tricks and suggestions on how it can be optimized.

There is a whole list of checks it supports which can be found here. By default, all checks are enabled except for the following ones:

  • ST1000: Incorrect or missing package comment
  • ST1005: Incorrectly formatted error string

These default settings can be changed in the configuration file:

 1{
 2    "project": {
 3        "name": "go-example",
 4        "version": "1.0.0",
 5        "description": "",
 6        "copyright": "",
 7        "main_package": "github.com/pieterclaerhout/go-example/cmd/go-example"
 8    },
 9    "staticcheck": {
10        "checks": [
11            "all",
12            "-ST1005",
13            "-ST1000"
14        ]
15    }
16}

Visual Studio Code settings

When you create a new project or init an existing project, a .vscode/settings.json file is now also created.

It's main purpose is to ignore files which shouldn't be watched or searched.

Download

You can download version 1.5.0 from here.