Is there a canonical way to add build scripts to a Go project?

1.2k Views Asked by At

Coming from the Node.js world, whenever you need a script (such as a build script there), a very common way of handling this is by adding it to the scripts block in the package.json file, so that you can the script by calling npm run <scriptname>. In other words, Node.js (respectively npm) has a built-in way to deal with (simple) scripts.

Does an equivalent to this exist in the Go world?

To put it differently: Suppose I have some commands such as doing a build, cleaning the build directory, creating a new version, and so on, is there a better way to do this than by adding a bunch of (platform-dependant) Bash script files?

In case there isn't – is there at least a common way of where to put these scripts? Or is this all left to the developer?

1

There are 1 best solutions below

0
On

You can use Makefile

this one is what I use sometimes:

BINARY_NAME=main
 
build:
    go mod tidy
    go build -o ${BINARY_NAME} main.go
 
clean:
    go clean
    rm ${BINARY_NAME}