typical-rest-server

module
v0.8.35 Latest Latest
Warning

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

Go to latest
Published: Jul 27, 2020 License: MIT

README

typical-rest-server

Go-Workflow Go Report Card codebeat badge codecov

The aims of project is provide simple, straight-forward and easy-to-adopt Rest-Server implementation in Go.

How to Use

  • Use the project as reference for project layout and code best practice.
  • The pkg package is general library that can help in various needs

Prerequisite

Quick Start

The project using typical-go as its build-tool.

./typicalw docker up   # equivalent with `docker-compose up -d` (if infrastructure not up)
./typicalw pg reset    # drop, create and migrate postgres database (if database not ready)
./typicalw mock        # generate mock (if require mock)

./typicalw test        # run test 

./typicalw run         # run the application

Project Layout

  • internal Exclusive go source files for the project
    • internal/app main functionality/entry-point
    • internal/infra infrastructure for the project e.g. config and connection object
    • internal/profiler for profiling the project e.g. HealthCheck, PProf, etc
    • internal/server REST-Server actual code
  • pkg Shareable go source files e.g. helper/utitily Library
  • api Any related scripts for API e.g. api-model script (swagger, raml, etc) or client script
  • databases Any related scripts for Databases e.g. migration scripts and seed data
  • tools External program that used by the project
  • typical Build-Tool descriptor

Layered Architecture

  • controller
    • Handling HTTP routes
    • Parsing the request
    • Sending response (both success & error)
  • service
    • Intermediary between controller (end-point) and repository (data)
    • Logic of controller
    • Data Validation
    • DTO (Data Transfer Object) Model
  • repository
    • Data access layer
    • No logic except operation to database
    • Repository pattern
    • DAO (Data Access Object) Model
    • Database Entity or Business Entity

Annotations

The project utilize Typical-Go annotation for code generation

  • @ctor functions will be provided in dig service-locator
  • @dtor functions will be execute when program end
  • @mock interfaces is target for mock generation

Configurations

Config in environment as 12factor recommentation. The build-tool (typical-go) will load values in .env file and generated it if not available.

Pg-Tool

Simple CLI to prepare the database learn more

./typicalw pg

Pkg Library

3rd Party Library

Concepts

Golang References

Project Status

The project status is WIP (Work in progress), means the author plan to continously improve and add more best-practices.

License

This project is licensed under the MIT License - see the LICENSE.md file for details

Directories

Path Synopsis
EXPERIMENTAL
cmd
internal
app
server/repository_mock
Package repository_mock is a generated GoMock package.
Package repository_mock is a generated GoMock package.
server/service_mock
Package service_mock is a generated GoMock package.
Package service_mock is a generated GoMock package.
pkg
tools
mysql-tool command
pg-tool command
typical-build command

Jump to

Keyboard shortcuts

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