How Can I Use Go for Scripting in My Work?

0
6
Asked By CuriousCoder92 On

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

Answered By DevGuru123 On

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.

NerdyNina -

Would `go vendor` serve as an alternative to `go get` for package management?

Answered By ScriptSavant77 On

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!

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.