go-cloud-learning-01-http
From zero to hero : Learning how to build your first «Todos» api server in Go.
Requirements
- Have access to a Linux Ubuntu 20.04 box or VM
- Install GO : https://golang.org/doc/install
- Pick your favorite editor like vim or maybe vscode
- Get a basic knowledge of GO : https://go.dev/learn/
Project Layout and conventions
This project uses the Standard Go Project Layout : https://github.com/golang-standards/project-layout
Where do I start ?
- just clone this repo in you Linux Box : git clone https://github.com/lao-tseu-is-alive/go-cloud-learning-01-http.git
- cd into the cloned repo directory
- install all project dependencies with : go get -d ./...
- then jump directly to your first example in cmd/00-http-basic
- have a look to the code in main.go file
- just run it : go run main.go
- hack-it, modify-it and have fun !
- Follow along with the other 3 examples in cmd directory:
- 01-http-envconfig-template-parameter : learn how to use env variables for config and reading a parameter
- 02-http-refactor-graceful-shutdown : learn about using a logger and code like a pro implementing «graceful» shutdown
- 03-http-json-todo : implement a basic "todos" API using Echo micro framework.
9.When you are ready, jump to the main example of this TODOS Api Server
Main example is a template Go project
You can use this repository as a base template for your future projects.
You can try it with :
make db-docker-init-data
make run
The first command will start a docker postgres container, create a database,
do a db migration up to create the necessary tables, and load some test data.
The next command will compile and run your todosServer, injecting version info based on your git tag,
and using your .env files to initialize the env variables.
The main features of this template are :
- A Makefile with more than 14 ready to use sub-commands (you can try : make help).
- Echo : High performance, extensible, minimalist Go web framework
- Contract based development using OpenAPI 3, (also called swagger in the past).
- Go server code generation from OpenApi spec using oapi-codegen
- Database migration using golang-migrate
- Table Driven Testing
- Live reload with **make fswatch
- Server version defined automatically based on your git tags semantic versioning. For example 0.1.1 git tag -a v0.1.1 -m "v0.1.1"
Useful Links