go-sample

module
v1.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 17, 2021 License: MIT

README

go-sample

GitHub release CI 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
├── cmd
│   └── cli                 // Entry point for the application.
├── commands                // Sub-commands for CLI (stands for Command Line Interface).
│   ├── migrate.go          // Migration sub-command. It creates, applies, and rollbacks DB-migrations.
│   └── server.go           // Server sub-command. It runs the HTTP server.
├── 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.
│       ├── log             // Convenient logger to decouple from the standard log package.
│       └── service         // Service-related reusable code: error handling for the service layer, etc.
└── migrate                 // Reusable migration utilities.
    └── migratorions        // This folder contains *.sql migrations.

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.
  • Reuse DB connection in tests.

Directories

Path Synopsis
cmd
cli
internal
infrastructure/log
Package log is a generated GoMock package.
Package log is a generated GoMock package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL