Alright, let's go! We'll keep this part short, so you can start building. ๐
First, make sure you have Go, git, and Docker installed. Then:
On your terminal in the project directory, run:
$ git remote add golangdk https://github.com/golangdk/canvas.git && git fetch golangdk
This will make it easier to keep up to date with changes from the original canvas repository.
You will now have a very basic Go project structure with a few config files, a Makefile, and the initial files for your Go program.
Everyone has different preferences for project structure, and there is no right way to do it. That said, in canvas we follow some conventions that work quite well:
go.mod
/go.sum
files, the Makefile
, and more, are in the root folder.cmd/server/
directory has the main
package and function that starts the server.server/
directory will hold the HTTP server setup and running code.handlers/
directory will have all the HTTP handlers.The Makefile
is a convenience so that we have to type less. It uses the go
command for testing, coverage, and starting the server.
Try running make start
, and you should see a nerdy smiley on your terminal:
$ make start
go run cmd/server/*.go
๐ค
To run your tests and see coverage, run make test cover
:
$ make test cover
go test -coverprofile=cover.out -short ./...
? canvas/cmd/server [no test files]
? canvas/handlers [no test files]
ok canvas/server 0.286s coverage: [no statements] [no tests to run]
go tool cover -html=cover.out
That's what you need to know for now. Next, let's write some code!
Get help at support@golang.dk.