#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.6.0, the followings things are changed/updated/fixed:

  • Added the option to build and publish your app as a Docker image
  • Added the option to create a GitHub action
  • Conditional create commands
  • Added support for installing go-james via Homebrew
  • Smaller bugfixes

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

Publish a Docker container

When you create a new project with docker files, it will also allow you to specify the repository to which the image should be pushed:

1"docker-image": {
2    "name": "go-james",
3    "repository": "pieterclaerhout/go-james",
4    "tag": "version",
5    "prune_images_after_build": true
6}

Additionally, you can specify a couple of extra settings:

  • tag: either release or version which indicates which of the two values should be used as the tag of the image.

  • prune_images_after_build: executes docker image prune -f after building the image.

GitHub Action

If you add the option --with-github-action, the following sample GitHub action file will be created under .github/workflows/build.yaml. It will test, run staticcheck and build the app storing the resulting assets.

 1name: Build and Publish
 2
 3on: [push]
 4
 5jobs:
 6
 7  build-test-staticcheck:
 8    name: Build, Test and Check
 9    runs-on: ubuntu-latest
10    steps:
11
12    - name: Set up Go 1.14
13      uses: actions/setup-go@v1
14      with:
15        go-version: 1.14
16      id: go
17
18    - name: Environment Variables
19      uses: FranzDiebold/github-env-vars-action@v1.0.0
20
21    - name: Check out code into the Go module directory
22      uses: actions/checkout@v2
23      with:
24        lfs: true
25
26    - name: Restore Cache
27      uses: actions/cache@preview
28      id: cache
29      with:
30        path: ~/go/pkg
31        key: 1.14-${{ runner.os }}-${{ hashFiles('**/go.sum') }}
32
33    - name: Get go-james
34      run: |
35        go get -u github.com/pieterclaerhout/go-james/cmd/go-james        
36
37    - name: Get dependencies
38      run: |
39        go get -v -t -d ./...        
40
41    - name: Build
42      run: |
43        export PATH=${PATH}:`go env GOPATH`/bin
44        go-james build        
45
46    - name: Test
47      run: |
48        export PATH=${PATH}:`go env GOPATH`/bin
49        go-james test        
50
51    - name: Staticcheck
52      run: |
53        export PATH=${PATH}:`go env GOPATH`/bin
54        go-james staticcheck        
55
56    - name: Package
57      run: |
58        export PATH=${PATH}:`go env GOPATH`/bin
59        go-james package        
60
61    - uses: actions/upload-artifact@v2
62      name: Publish
63      with:
64        name: ${{ env.GITHUB_REPOSITORY_NAME }}-${{ env.GITHUB_SHA_SHORT }}-${{ env.GITHUB_REF_NAME }}.zip
65        path: build/*.*

Conditional create commands

The option --create-git-repo has been renamed to --with-git which is easier to remember and less confusing. Two additional ones were added (both false by default):

  • --with-docker: creates the .dockerignore and Dockerfile files

  • --with-github-action: creates a sample .github/workflows/build.yaml file

Install via homebrew

To make the install easier, you can now install via homebrew:

First, install the correct tap.

1$ brew tap pieterclaerhout/go-james
2==> Tapping pieterclaerhout/go-james
3Cloning into '/usr/local/Homebrew/Library/Taps/pieterclaerhout/homebrew-go-james'...
4remote: Enumerating objects: 4, done.
5remote: Counting objects: 100% (4/4), done.
6remote: Compressing objects: 100% (4/4), done.
7remote: Total 4 (delta 0), reused 4 (delta 0), pack-reused 0
8Receiving objects: 100% (4/4), done.
9Tapped 1 formula (27 files, 26.5KB).

Then, install (or update):

1$ brew install go-james
2==> Installing go-james from pieterclaerhout/go-james
3==> Downloading https://github.com/pieterclaerhout/go-james/releases/download/v1.6.0/go-james_darwin_amd64.tar.gz
4######################################################################## 100.0%
5🍺  /usr/local/Cellar/go-james/1.6.0: 4 files, 11.5MB, built in 3 seconds

Download

You can download version 1.6.0 from here.