Git Product home page Git Product logo

chi-gorm's Introduction

chi-gorm

Experimental project using Chi and GORM

Starting the server

Setup database

psql
> CREATE DATABASE chi_gorm

# Be sure to update main.go with your database credentials
# install yolo - for hot reloading
go get github.com/azer/yolo

# starts development mode
make start

Folder structure

Structure is inspired by https://manuel.kiessling.net/2012/09/28/applying-the-clean-architecture-to-go-applications/; accepting only the principles that I like and getting rid of other notions that I deem less important.

/
|- controllers
|- config
|- dal
|- interfaces (implemented in the future)
|- lib
|- models
|- migrations
|- services
main.go
router.go

Controllers - hosts the handlers of all requests coming in. Business logic and data access layer should be done separately. This is done to decouple the system.

Config - hosts setup for the sytem to connect to external data source or any other things related to the infrastructure of the sytem. Hosts things like database connection configurations.

DAL - data access layer. All queries and data operations should happen here.

lib - arbitrary libraries that do not fit in the other directories.

Interfaces - the bridge that allows two different entities to interact with each other. For example, if the controller wants to talk to services, UserController will implement IUserService ("I" indicating interface), and in turn IUserService will be injected with UserService. This will be implemented in the future since Dependency Injection requires a lot of operations overhead.

models - contains structs reflecting our data object from database.

migrations - where the database migrations reside.

services - where the business logic should live. Handles controller requests and fetch data from data access access layer.

main.go - entry point of our system.

router.go - where we bind controllers to routes.

Database migrations

Database migrations are not versioned since we are going to use Gorm's AutoMigrate functionality to reduce complexity. This means that when you update the model, and you push this update to production, the database will be automatically changed. Note that this might break functionality in the case of backwards incompatible changes, and so it must be done with caution.

chi-gorm's People

Contributors

obedtandadjaja avatar

Watchers

 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.