go-cloud-learning-01-http

module
v0.1.11 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 9, 2021 License: MIT

README

go-cloud-learning-01-http

From zero to hero : Learning how to build your first «Todos» api server in Go.

Requirements

  1. Have access to a Linux Ubuntu 20.04 box or VM
  2. Install GO : https://golang.org/doc/install
  3. Pick your favorite editor like vim or maybe vscode
  4. 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 ?

  1. just clone this repo in you Linux Box : git clone https://github.com/lao-tseu-is-alive/go-cloud-learning-01-http.git
  2. cd into the cloned repo directory
  3. install all project dependencies with : go get -d ./...
  4. then jump directly to your first example in cmd/00-http-basic
  5. have a look to the code in main.go file
  6. just run it : go run main.go
  7. hack-it, modify-it and have fun !
  8. Follow along with the other 3 examples in cmd directory:
    1. 01-http-envconfig-template-parameter : learn how to use env variables for config and reading a parameter
    2. 02-http-refactor-graceful-shutdown : learn about using a logger and code like a pro implementing «graceful» shutdown
    3. 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"

Directories

Path Synopsis
cmd
03-http-json-todo
Package main provides primitives to interact with the openapi HTTP API.
Package main provides primitives to interact with the openapi HTTP API.
internal
todos
Package todos provides primitives to interact with the openapi HTTP API.
Package todos provides primitives to interact with the openapi HTTP API.
pkg

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL