Skip to content

viniciuspra/go-api-starter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

go-api-starter

A clean Go API template with layered architecture, PostgreSQL integration, and versioned routing.

Features

  • Chi router with versioned endpoints (/v1)
  • PostgreSQL with sqlc code generation
  • Structured logging with slog
  • Configuration management with envconfig
  • CORS middleware
  • User management endpoints

Requirements

  • Go 1.25+
  • Docker
  • Make
  • Goose (for migrations)

Setup

Environment

Copy and configure the environment file:

cp .env.example .env

Set your database credentials and port.

Database

Start PostgreSQL container:

make p-up

Run migrations:

make m-up

Build

make build

Running

make run

Server starts on the port defined in .env.

API Endpoints

  • GET /v1/health - Health check
  • GET /v1/users - List active users
  • POST /v1/users - Create user
  • GET /v1/users/{id} - Get user by ID
  • PUT /v1/users/{id} - Update user
  • DELETE /v1/users/{id} - Deactivate user

Database Queries

Queries are in internal/database/queries/. After modifying, regenerate with:

make sqlc

License

MIT

About

Go API template

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors