Skip to content

Fiber, Postgres, JWT and Swagger docs in isolated Docker containers

Notifications You must be signed in to change notification settings

cooljar/go-postgres-fiber

Repository files navigation

📖 Tutorial: Build a RESTful API on Go using Fiber and Postgres

Fiber, Postgres, JWT and Swagger docs in isolated Docker containers.

Getting Started

These instructions will get you a copy of the project up and running on docker container and on your local machine.

Prerequisites

Prequisites package:

Optional package:

  • gosec Golang Security Checker

Running In Docker Container

  1. Rename Makefile.example to Makefile and fill it with your make setting.
  2. Run project by this command:
$ make run

# Process:
#   - Generate API docs by Swagger
#   - Create a new Docker network for containers
#   - Build and run Docker containers (Fiber, PostgreSQL)
#   - Apply database migrations (using github.com/golang-migrate/migrate)

Stop application by this command:

$ make stop

# Process:
#   - Stop and remove postgres container
#   - Stop and remove Fiber container

Running On Local Machine

  1. Create local database by running command createdb some_database_name
  2. Rename run.sh.example to run.sh and fill it with your environment values.
  3. Set run.sh file permission
$ chmod +x ./run.sh
  1. Run application from terminal by execute this command:
$ ./run.sh
  1. Go to your API Docs page: 127.0.0.1:3000/swagger/index.html

To reset database, run following command.

$ migrate -path ./platform/migrations -database "postgres://username:password@localhost:5432/db_name?sslmode=disable" down

API Access

Go to your API Docs page: 127.0.0.1:3000/swagger/index.html
API Docs page will be look like:

Testing

  • Inspects source code for security problems using gosec. You need to install it first.
  • Execute unit test
$ make test

Testing

  • Inspects source code for security problems using gosec. You need to install it first.
  • Execute unit test by using following command:
$ make test

Built With

  • Go - Go Programming Languange
  • Go Modules - Go Dependency Management System
  • Make - GNU Make Automated Execution
  • Docker - Application Containerization

Authors

  • Fajar Rizky - Initial Work - cooljar

More


About

Fiber, Postgres, JWT and Swagger docs in isolated Docker containers

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages