Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/titusjaka/go-sample
Go Backend Sample with the modular structure.
https://github.com/titusjaka/go-sample
backend clean-architecture golang postgres restful-api
Last synced: 3 months ago
JSON representation
Go Backend Sample with the modular structure.
- Host: GitHub
- URL: https://github.com/titusjaka/go-sample
- Owner: titusjaka
- License: mit
- Created: 2021-01-31T08:43:14.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2024-05-06T10:09:14.000Z (8 months ago)
- Last Synced: 2024-05-07T09:47:15.404Z (8 months ago)
- Topics: backend, clean-architecture, golang, postgres, restful-api
- Language: Go
- Homepage:
- Size: 166 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# go-sample
[![GitHub release](https://img.shields.io/github/v/release/titusjaka/go-sample)](https://github.com/titusjaka/go-sample/releases/latest)
[![codecov](https://codecov.io/gh/titusjaka/go-sample/branch/main/graph/badge.svg?token=UNJY7V5SZL)](https://codecov.io/gh/titusjaka/go-sample)
[![Go Report Card](https://goreportcard.com/badge/github.com/titusjaka/go-sample)](https://goreportcard.com/report/github.com/titusjaka/go-sample)
[![GitHub license](https://img.shields.io/github/license/titusjaka/go-sample)](https://github.com/titusjaka/go-sample/blob/main/LICENSE)Go Backend Sample. Itβs suitable as a starting point for a REST-API Go application.
This example uses:
- [chi](https://github.com/go-chi/chi) for HTTP router;
- [kong](https://github.com/alecthomas/kong) for building neat commands;
- [PostgreSQL](https://www.postgresql.org/) as a database and [pgx](https://github.com/jackc/pgx) as a driver;
- [testify](https://github.com/stretchr/testify) and [mock](https://github.com/uber-go/mock) for tests;
- [ozzo-validation](https://github.com/go-ozzo/ozzo-validation) for request validation;
- [slog](https://go.dev/blog/slog) as a logger;
- [the Clean Architecture](http://blog.cleancoder.com/uncle-bob/2012/08/13/the-clean-architecture.html) as the primary approach.Features:
- Modular Project Structure.
- Built-in migration handling.
- Ready to go example with tests and mocks.
- Easy-to-go Docker deployment.## Structure
```text
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
```shell
git clone https://github.com/titusjaka/go-sample
```## Usage
```shell
docker-compose up --build
```## Future improvements
- [ ] Return verbose API errors with exact fields in it:
```json
{
"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.