Go Tool

Is Go Tool for little ole me? Yes.

This is not to be confused with my previous post, Go Toolchain!

I've been working some of my tools more and more into my side projects. Things like CRUDGEON and JTML. I have a new small side project that I haven't yet made public, and also I converted AltarSchedule to use JTML. The need for this is obvious, as they are tools that are made to make things easier. Even if I'm updating it retroactively, the idea is that if I need to go back and make new updates, it'll be easier to read and make updates.

Recently I remembered “go tool”. I've known about it for a long time, and struggled to see how my own things that I write would be considered Go Tools, and be needed to be integrated into my projects as such. Well, that became very obvious recently.

I work on many computers. And on this particular computer, I haven't cloned the repo for CRUDGEON yet, so it's just not there. On another computer, I was on a different branch, and another computer didn't have the latest version. This is a huge pain for something that is definitely needed in all places where I have to work on the project that uses CRUDGEON. Go Tool solved this incredibly well.

So basically, I tell my repository (go.mod file) that it needs to have the go tool called CRUDGEON located at this path on the internet, and use this particular version. Then I rewrite my “gen.ps1” script which calls crudgeon.exe (and assumes it's installed, and it's the right version), with the command line arguments and the data in the repo to correctly and predictably generate the code.  So now it calls it with the “go tool” command line, instead of calling it as if it were installed globally.

This gets me many things. First, each place I clone this repo, it will also correctly install CRUDGEON, the correct version etc, on that machine as well, without me having the code there or having the latest on that computer if I did have the code. It will make sure the version of it that is installed is what the go.mod file is expecting, and if it's not, update it. I could have written tons of powershell script and added it to my project to do this, but I don't have to. Next, it runs it predictably wherever I choose to run it. Same version everywhere. If I update the version in the repo, it will update it automatically wherever I get latest and run that command. Here's what that looks like now (I typically set up my project to be docker compose friendly, so the code goes in ./svc and I use a go.work file)

cd svc
go tool github.com/jasontconnell/crudgeon/cmd/crudgeon -config ../crudgeon/config.json -dir ../crudgeon/source -path ../
go tool github.com/jasontconnell/jtml/cmd/jtml -src ./jtml -dest ./template2
gofmt -w ./
cd ..

This is amazing (and gives no hints about my new project :D )