Skip to content

Go Echo API template with Docker, live reload, SQLC and Goose migrations

License

Notifications You must be signed in to change notification settings

laaraujo/go-echo-api-sample

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Golang Echo API

Sample Rest API project I made while learning some Go and Echo

Table of Contents

Overview

This project intends to serve as a template to kickstart Go API development with Echo framework.

Features

  • Database schema and migrations with Goose
  • Type-safe SQL interfaces with sqlc
  • Local development setup with Docker, Docker Compose, Make
  • Live reload with Air in Docker
  • Very basic placeholder auth middleware with API_KEY

Installation

Setup your local environment with the following commands

# Install goose and sqlc locally
$ make setup
# Build your containers
$ make build

Usage

Run locally

# Start your containers
$ make run

Then in another shell:

# Update your database schema by applying the migrations
$ make goose/migrate

Create a new migration file

$ make goose/create
  • Note: this will create a file with the default name *_rename_this_file.sql so you may want to rename it.

Generate SQLC types

$ make sqlc/generate

Stop local containers

$ make stop

Production Docker image

If you want to test your Docker image:

# Build your image
$ docker build -f docker/Dockerfile -t golang-echo-api .
# Replace the corresponding env vars and run it!
$ docker run -p 8000:<PORT> -e PORT=<PORT> -e DATABASE_URL=<database_url> -e API_KEY=<api_key> golang-echo-api
  • If you want to use your local DB to test this build you can use host.docker.internal in your database url env var parameter (i.e. -e DATABASE_URL=postgresql://postgres:[email protected]:5432/postgres)

License

This project is licensed under the MIT License - see the LICENSE file for details.