Giter VIP home page Giter VIP logo

go-clean-template's Introduction

Go clean architecture template

This is a template for Go project with clean architecture.

Folder structure

go-clean-template
├── cmd
│   ├── httpserver
│   └── migrate
├── entity/domain/model
├── handler //as controller
│   └── httpserver
│       ├── middleware
│       ├── model
│       ├── options.go
│       ├── server.go
│       └── *_handler.go //handle request to client
├── infras
│   ├── paymentsvc //call API to payment service provider
│   ├── notification //push noti
│   └── postgrestore
│       ├── schema
│       ├── postgresql.go //contains actions to connect DB
│       └── *_repo.go //implement repository interfaces
├── migrations  //contains migration files
├── pkg // contains common packages
│   ├── apperror
│   ├── config
│   ├── constant
│   ├── logger
│   ├── sentry
│   └── validation
├── tools
│   ├── compose
│   └── pre-commit
└── usecase
    ├── mocks //contains mock files used for unit testing
    ├── interface.go //contains all interfaces
    └── ... //specific usecases

Development

Init local environment

  1. Copy file .env.example and rename to .env

  2. Update env vars to fit your local

  3. Start local services

    make local-db
  4. Run the server

    make run
  5. Unit test

    make test
  6. Generate Mock

     make mock

Linting

make lint

Create new migration file

sql-migrate new -env="development" Init-database
  • Result: Created migration migrations/20240704092049-Init-database.sql

Then run migration:

make db/migrate

go-clean-template's People

Contributors

quangpn24 avatar teq-quangphan avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.