DEV Community

Jaga santagostino
Jaga santagostino

Posted on • Originally published at jagascript.com on

2 2

How I Start New Go Projects in Seconds


For the past years, I’ve started using more and more golang as a scripting language, and since in the past we were forced to put code in the GOPATH it became a little cumbersome compared to just write a bash file in the current folder

Project goinit

goinit

So I created a go program called goinit to generate a new project in my GOPATH at ~/go/src/github.com/kandros/[project-name] and open it in my editor, so far it server me very well, every new experiment is just a couple keystroke away goinit my-app, I literally can see something in the console in less than 15 seconds

Using go mod

Since go 1.11 I’ve started using go modules and stopped using goinit, a couple days ago I decided to refactor it to handle creating projects outside GOPATH and decided to use an even simpler solution, a custom shell function

goinit() {
 mkdir -p ~/coding/$1
 cd ~/coding/$1
 cat <<-EOF > main.go
 package main

 import "fmt"

 func main() {
    fmt.Println("hello")
    }
 EOF

 go mod init github.com/kandros/$1
 code-insiders --new-window . --goto main.go
}

It works the same way as my previous script by running goinit new-project in the terminal it will create the folder ~/coding/new-project open the project in VScode and the file main.go

Make the function accessible globally

This function is stored in my ~/.zshrc file to be available in the terminal, Bash users can put it in their ~/.bash_profile

Playwright CLI Flags Tutorial

5 Playwright CLI Flags That Will Transform Your Testing Workflow

  • 0:56 --last-failed
  • 2:34 --only-changed
  • 4:27 --repeat-each
  • 5:15 --forbid-only
  • 5:51 --ui --headed --workers 1

Learn how these powerful command-line options can save you time, strengthen your test suite, and streamline your Playwright testing experience. Click on any timestamp above to jump directly to that section in the tutorial!

Watch Full Video 📹️

Top comments (0)

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay