README.md

REST API Base Go #

A REST API authentication service built with Go, Fiber, PostgreSQL, and sqlc.

Features #

  • HTTP Framework (Fiber)
  • Database (PostgreSQL with sqlc)
  • Migrations (golang-migrate)
  • Authentication (JWT)
  • Password Hashing (bcrypt)

Requirements #

Setup #

  • Copy .env.example to .env and adjust as needed
  • Install dependencies: go mod download

Migrations #

Apply migrations:

make migrate

Create new migration:

migrate create -ext sql -dir internal/migrations -seq migration_name

Development #

Run with hot-reload:

make dev

Or build and run:

make build
./bin/api

API Endpoints #

Method Endpoint Description
GET / Get current user
POST /auth/register Register new user
POST /auth/token Login
POST /auth/refresh Refresh token

Usage #

Register a new user:

curl -X POST http://localhost:3000/auth/register \
  -H "Content-Type: application/json" \
  -d '{"phone_number": "+5511999999999", "password": "secret", "email": "user@example.com"}'

Login:

curl -X POST http://localhost:3000/auth/token \
  -H "Content-Type: application/json" \
  -d '{"phone_number": "+5511999999999", "password": "secret"}'

Get current user:

curl -X GET http://localhost:3000/ \
  -H "Authorization: Bearer <access_token>"

Refresh token:

curl -X POST http://localhost:3000/auth/refresh \
  -H "Content-Type: application/json" \
  -d '{"refresh_token": "<refresh_token>"}'