A simple RESTful API for managing users, contacts, and addresses, built with Go, Fiber, and GORM.
This project is created for learning purposes only.
User API:
- Register a user
- Login & generate token
- Get current user
- Update current user
- Logout (invalidate token)
Contact API (protected):
- Create a contact
- Search & list contacts (with pagination & filters)
- Get contact by ID
- Update contact
- Delete contact
Address API (protected):
- Create address for a contact
- List all addresses for a contact
- Get address by ID
- Update address
- Delete address
General Features:
- Authentication with token (UUID) via Authorization header
- Input validation using
go-playground/validator
- Consistent JSON response format (
data
,errors
) - Layered architecture (Handler → Usecase → Repository → Entity)
- OpenAPI 3.0 specification (YAML file included)
Language:
- Go 1.22+
Framework & Libraries:
- Fiber – Web framework for routing
- GORM – ORM for Go
- PostgreSQL Driver for GORM
- Go Playground Validator – Struct validation
- Logrus – Logging
- Viper – Configuration management
Database:
- PostgreSQL 14+ (or compatible)
git clone https://github.com/jonathangunawan30/golang-contact-management-restful-api.git
go mod tidy
Edit config.yaml
:
server:
port: "3000"
database:
url: "postgres://postgres:postgres@localhost:5432/dbname?sslmode=disable"
Make sure PostgreSQL is running and the database exists.
Install golang-migrate
CLI if you haven’t:
go install -tags 'postgres' github.com/golang-migrate/migrate/v4/cmd/migrate@latest
Run migration:
migrate -path migrations -database "postgres://postgres:postgres@localhost:5432/dbname?sslmode=disable" up
go run main.go