joey1123455 / beds-api

a boiler plate for gin monolith projects

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Project Setup

This guide will help you set up the necessary tools to work on this project. You'll be installing the Go compiler, Docker, Docker Compose, sqlc, and the Go Migrate CLI.

1. Install Go Compiler

Go to the official Go website and download the installer for your operating system.

For Windows:

  1. Download the MSI installer from the Go downloads page.
  2. Run the MSI installer and follow the prompts.

For macOS:

  1. Download the package file from the Go downloads page.
  2. Open the package file and follow the instructions to install.

For Linux:

Use the following commands to download and install Go (replace VERSION with the latest Go version, e.g., 1.20.6):

wget https://golang.org/dl/goVERSION.linux-amd64.tar.gz
sudo tar -C /usr/local -xzf goVERSION.linux-amd64.tar.gz

Add Go to your PATH by adding the following line to your .bashrc or .zshrc file:

export PATH=$PATH:/usr/local/go/bin

Reload your shell configuration:

source ~/.bashrc
# or
source ~/.zshrc

Verify the installation:

go version

2. Install Docker

Follow the instructions on the Docker website to install Docker for your operating system.

For Windows and macOS:

  1. Download Docker Desktop from the Docker downloads page.
  2. Run the installer and follow the prompts.

For Linux:

Use the official Docker installation script:

curl -fsSL https://get.docker.com -o get-docker.sh
sh get-docker.sh

Verify the installation:

docker --version

3. Install Docker Compose

Follow the instructions on the Docker Compose website to install Docker Compose for your operating system.

For Windows and macOS:

Docker Compose is included with Docker Desktop.

For Linux:

Run the following commands:

sudo curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose

Verify the installation:

docker-compose --version

4. Install sqlc

Follow the instructions on the sqlc website to install sqlc.

Using Homebrew (macOS and Linux):

brew install sqlc

Using Go (all platforms):

go install github.com/kyleconroy/sqlc/cmd/sqlc@latest

Verify the installation:

sqlc version

5. Install Go Migrate CLI

Follow the instructions on the migrate website to install the Go Migrate CLI.

Using Homebrew (macOS and Linux):

brew install golang-migrate

Using Go (all platforms):

go install -tags 'postgres' github.com/golang-migrate/migrate/v4/cmd/migrate@latest

Verify the installation:

migrate -version

Makefile Instructions

The Makefile contains various commands to manage database migrations, run tests, ensure code quality, and build the project. Below are the available targets and their descriptions:

General Commands

  • help: Display this help message.

    make help

SQL Migrations

  • create-migration: Create a new migration file for a table.

    make create-migration table_name=<table_name>
  • migrate-force: Force a migration to a specific version.

    make migrate-force version=<version>
  • migrate-up: Migrate the database schema up to the latest version.

    make migrate-up
  • migrate-down: Rollback the database schema back

    make migrate-down
  • migrate-drop: Drop all database tables.

    make migrate-drop
  • migrate-to: Migrate the database schema to a specific version.

    make migrate-to version=<version>

Testing

  • test: Run all tests with coverage and race detection.

    make test

Code Quality Check

  • tidy: Format code and tidy the mod file.

    make tidy
  • audit: Run go vet and golangci-lint, and verify dependencies.

    make audit
  • lint: Run golangci-lint.

    make lint
  • lint-fix: Run golangci-lint with fix option.

    make lint-fix

SQLC ORM CLI

  • sqlc-gen: Generate code using sqlc.

    make sqlc-gen

Build

  • docker-compose-up: Build and start Docker Compose services.

    make docker-compose-up
  • docker-compose-down: Stop Docker Compose services.

    make docker-compose-down
  • build-artifact: Build the project for Linux.

    make build-artifact

Mock Generation

  • mock: Generate mock implementations for testing.

    make mock

About

a boiler plate for gin monolith projects


Languages

Language:Go 84.2%Language:HTML 7.1%Language:Shell 4.2%Language:Makefile 3.4%Language:Dockerfile 1.1%