Hey everyone! I've been using Bash, Python, and JavaScript for scripting at work, especially for pipelines and automation. I'm fairly new to Go and want to know how to leverage it for my tasks. Can you share any tips or examples from your experiences? Also, do I need to always run a "go build" beforehand, or are there other ways to use Go in a scripting context?
2 Answers
You can also use `go run` to execute your Go scripts directly, but you need to have the packages already or use `go get` first. However, for efficiency, it's usually better to build and publish your binaries for your pipeline to pull, or include them directly in your Docker image.
You should definitely check out `go install`! It works similarly to `npx` for JavaScript. Basically, if you have a script or CLI tool, running `go install .` will compile it and place it in your GOPATH/bin. This way, you can run it like any command without needing to build it every time! For example, you can do `go install github.com/cli/cli/v2/cmd/gh@latest` to get the latest GitHub CLI installed as a binary. It's super handy!
Would `go vendor` serve as an alternative to `go get` for package management?