Skip to content

Instantly share code, notes, and snippets.

@iwittkau
Last active July 24, 2019 08:45
Show Gist options
  • Save iwittkau/19ade8d55601dd339d9c3b095c940232 to your computer and use it in GitHub Desktop.
Save iwittkau/19ade8d55601dd339d9c3b095c940232 to your computer and use it in GitHub Desktop.
This is a function I keep in my .bashrc / .zshrc to open a local Go playground for quick prototyping or tests.
# Quickly jumpstart a local go playground
# This is a function I keep in my .bashrc / .zshrc to open a local Go playground for quick prototyping or tests.
# If you use something other than macOS and Visual Studio Code you have to edit line 14.
#
# Example:
#
# $ goplay test
#
# This will create `~/go/src/playground/test` containing a `main.go` and runs `go mod init playground/tes`
#
function goplay() {
mkdir -p ~/go/src/playground/$1
printf "package main\n\nfunc main() {\n\n}" > ~/go/src/playground/$1/main.go
open -a 'Visual Studio Code' ~/go/src/playground/$1
cd ~/go/src/playground/$1 && go mod init playground/$1
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment