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:

FROM golang:alpine AS mod-download

RUN apk update && apk add git && rm -rf /var/cache/apk/*
RUN GO111MODULE=on go get -u github.com/pieterclaerhout/go-james/cmd/go-james

RUN mkdir -p /app

ADD go.mod /app
ADD go.sum /app

WORKDIR /app


RUN go mod download

FROM mod-download AS builder

ADD . /app
WORKDIR /app

RUN CGO_ENABLED=0 go-james build -v


FROM scratch

COPY --from=builder "/app/build/go-example" /

ENTRYPOINT ["/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:

go-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:

{
    "project": {
        "name": "go-example",
        "version": "1.0.0",
        "description": "",
        "copyright": "",
        "main_package": "github.com/pieterclaerhout/go-example/cmd/go-example"
    },
    "staticcheck": {
        "checks": [
            "all",
            "-ST1005",
            "-ST1000"
        ]
    }
}

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.