Created
July 30, 2026 10:52
-
-
Save OJOMB/4d02333c96c7b53821610a3bedc5ba42 to your computer and use it in GitHub Desktop.
sh function to init a go module directory for VSCode
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| gocreate() { | |
| if [ $# -ne 1 ]; then | |
| echo "Usage: gocreate <module-name>" | |
| return 1 | |
| fi | |
| local module="$1" | |
| mkdir -p "$module"/{cmd,internal,.vscode} | |
| cd "$module" || return | |
| go mod init "$module" | |
| git init | |
| cat > cmd/main.go <<'EOF' | |
| package main | |
| import "fmt" | |
| func main() { | |
| fmt.Println("Hello, world!") | |
| } | |
| EOF | |
| cat > .vscode/launch.json <<'EOF' | |
| { | |
| // Use IntelliSense to learn about possible attributes. | |
| // Hover to view descriptions of existing attributes. | |
| // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 | |
| "version": "0.2.0", | |
| "configurations": [ | |
| { | |
| "name": "Launch Package", | |
| "type": "go", | |
| "request": "launch", | |
| "mode": "auto", | |
| "program": "${workspaceFolder}/cmd/main.go" | |
| } | |
| ] | |
| } | |
| EOF | |
| cat > .gitignore <<'EOF' | |
| # Binaries for programs and plugins | |
| *.exe | |
| *.exe~ | |
| *.dll | |
| *.so | |
| *.so.* | |
| *.dylib | |
| # Test binary, built with `go test -c` | |
| *.test | |
| # Output of the go coverage tool | |
| *.out | |
| # Dependency directories | |
| vendor/ | |
| # Go workspace file | |
| go.work | |
| # IDE - VSCode | |
| .vscode/ | |
| *.code-workspace | |
| launch.json | |
| settings.json | |
| # IDE - GoLand / IntelliJ | |
| .idea/ | |
| *.iml | |
| *.iws | |
| *.ipr | |
| # IDE - Other | |
| .sublime-workspace | |
| .sublime-project | |
| *.swp | |
| *.swo | |
| *~ | |
| .DS_Store | |
| .vscode* | |
| # OS | |
| Thumbs.db | |
| .DS_Store | |
| # Environment files | |
| .env | |
| .env.local | |
| .env.*.local | |
| # Build output | |
| dist/ | |
| build/ | |
| bin/ | |
| # Temporary files | |
| *.tmp | |
| *.temp | |
| EOF | |
| echo "Created Go module '$module'" | |
| echo "Run 'code .' to open it in VS Code." | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment