Skip to content

Go Backend Sample with the modular structure.

License

Notifications You must be signed in to change notification settings

titusjaka/go-sample

Repository files navigation

go-sample

GitHub release codecov Go Report Card GitHub license

Go Backend Sample. It’s suitable as a starting point for a REST-API Go application.

This example uses:

Features:

  • Modular Project Structure.
  • Built-in migration handling.
  • Ready to go example with tests and mocks.
  • Easy-to-go Docker deployment.

Structure

go-sample
├── 📁 commands/              // Sub-commands for CLI (stands for Command Line Interface).
├── 📁 internal/              // Internal packages for the application according to Go convention.
│  ├── 📁 business/           // Business logic of the application.
│  │  └── 📁 snippets/        // A specimen business-logic package “snippets” with REST-API for snippets creating, listing, and deleting.
│  └── 📁 infrastructure/     // Infrastructure code of the application.
│     ├── 📁 api/             // API-related utilities: middlewares, authentication, error handling for the transport layer.
│     ├── 📁 kongflag/        // Helper package for Kong CLI.
│     ├── 📁 nopslog/         // No-operation logger for tests.
│     ├── 📁 postgres/        // PostgreSQL-related utilities.
│     │  ├── 📁 pgmigrator/   // PostgreSQL migration utilities.
│     │  └── 📁 pgtest/       // PostgreSQL test utilities.
│     ├── 📁 service/         // Service-related reusable code: error handling for the service layer, etc.
│     └── 📁 utils/ 
│        └── 📁 testutils/    // Test utilities.
├── 📁 migrations/            // This folder contains *.sql migrations.
└── main.go                   // Entry point for the application.

Installation

git clone https://github.com/titusjaka/go-sample

Usage

docker-compose up --build

Future improvements

  • Return verbose API errors with exact fields in it:
    {
      "errors": {
        "title": "Title must not be empty",
        "expires_at": "Expires at must be within range 1-365 days"
      }
    }
  • Add user authentication + session storage.
  • Add /status handler with service health.