Gonew: Simplifying Golang Project Setup!

gonew

gonew is a tool from the Go team that helps you clone an existing Go module (template/repo) into a new project with a new module path.

Its a handy tool for Golang developers. It lets you create a Go project structure from another one with just one command. And it updates all the package names based on your new project name, including updating the go.mod with the module name. So it’s not just simple cloning. How cool is that? ๐Ÿ˜Ž

Think of it like:

  • git clone + rename module

Although it’s experimental, I’ve tried it without any issues. Here’s how you can use it in just a few steps:

Installation: Start by installing the tool:

$ go install golang.org/x/tools/cmd/gonew@latest

Project Creation: Now, create a project structure from a Golang team example HTTP server with this command:

$ gonew github.com/monirz/goserve github.com/monirz/newproject

Get Started: That’s it! You can now navigate to the newproject directory and start using your new project, without updating the package/module names. ๐Ÿš€

Common use cases are:

  • Starting from the Go team’s official example templates (HTTP server, gRPC service, etc.)
  • Using your own internal starter templates across a team
  • Avoiding the boilerplate of go mod init + copying files + renaming imports

Gonew simplifies Golang project setup, making your development workflow more efficient. Give it a try and streamline your Go projects! ๐Ÿ‘จ๐Ÿ’ป