How to Create a Golang Project

Hey! If you love Go and building Go apps as much as I do, let's connect on Twitter or LinkedIn. I talk about this stuff all the time!

Want to learn how to build better Go applications faster and easier? You can.

Check out my course on the Go Standard Library. You can check it out now for free.


So, you’re probably wondering how to create a Go project. Like, how do people just start a project?

It’s easy. Open a command prompt.

Make a directory, in my case I named it “test”

use Go init to start a new project. You can make up the repo name, or if you actually have a Git repo for it, use that.

go mod init example.com/test

This will create a project and a go.mod file for you. You can use this to manage dependencies:

How to create a golang project

Now, create a main.go with some hello world code:

How to create a golang project

And save it.

Now you can type

go build

and build your file. Because I named mine example.com/test the binary it makes will be “test”:

How to create a golang project

And you can see the results of my file. It’s easy!!

Another way to run go Files

You can also run the individual file:

go run main.go

How to create a golang project

but here’s an even better way. Using “Make”. Create a file named makefile that looks like this:

build:
	go build

run: build
	./test

Save it, and type:

make run

How to create a golang project

This file will build, then run your application.

The advantage of doing this is, you can add environment variables, or complicated build strings and save them in this file, so running it super easy.

I hope this has helped.

Thanks for reading, and good luck on your Go adventures!



Stay up to date on the latest in Coding for AI and Data Science

Intuit Mailchimp