Code Monkey home page Code Monkey logo

clean-gin's Introduction


Project Overview

Clean architecture template with gin framework, go-fx as dependency container, gorm as orm for database related operations.

To learn about project structure and dependency injection please go through here

Want to ask something, contribute or be part of discussions, ๐Ÿ’ฌ Join us on Discord server.

Running the project

  • Make sure you have docker installed.
  • Copy .env.example to .env
  • Run docker-compose up -d
  • Go to localhost:5000 to verify if the server works.
  • Adminer Database Management runs at 5001 .

If you are running without docker be sure database configuration is provided in .env file and run go run . app:serve

Environment Variables

Variables Defined in the project
Key Value Desc
SERVER_PORT 5000 Port at which app runs
ENV development,production App running Environment
LOG_OUTPUT ./server.log Output Directory to save logs
LOG_LEVEL info Level for logging (check lib/logger.go:172)
DB_USER username Database Username
DB_PASS password Database Password
DB_HOST 0.0.0.0 Database Host
DB_PORT 3306 Database Port
DB_NAME test Database Name
JWT_SECRET secret JWT Token Secret key
ADMINER_PORT 5001 Adminer DB Port
DEBUG_PORT 5002 Port that delve debugger runs in

Migration Commands

โš“๏ธ ย  Add argument p=host if you want to run the migration runner from the host environment instead of docker environment. Check #19 for more details. eg; make p=host migrate-up

Migration commands available
Command Desc
make migrate-up runs migration up command
make migrate-down runs migration down command
make force Set particular version but don't run migration
make goto Migrate to particular version
make drop Drop everything inside database
make create Create new migration file(up & down)

Implemented Features

  • Dependency Injection (go-fx)
  • Routing (gin web framework)
  • Environment Files
  • Logging (file saving on production) zap
  • Middlewares (cors)
  • Database Setup (mysql)
  • Models Setup and Automigrate (gorm)
  • Repositories
  • Implementing Basic CRUD Operation
  • Authentication (JWT)
  • Migration Runner Implementation
  • Live code refresh
  • Dockerize Application with Debugging Support Enabled. Debugger runs at 5002. Vs code configuration is at .vscode/launch.json which will attach debugger to remote application. Learn More
  • Cobra Commander CLI Support. try: go run . --help

Todos

  • COBRA Commander CLI Support #26
  • Swagger documentation examples #25
  • Unit testing examples. #23
  • File upload middelware. #20
  • Use of Interfaces #10

Contributing

Please open issues if you want the template to add some features that is not in todos. ๐Ÿ™‡โ€โ™‚๏ธ

Create a PR with relevant information if you want to contribute in this template.

clean-gin's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

clean-gin's Issues

Add file upload middleware

Try to create a file upload middleware that is extensible (plug and playable) similar to multer in express.

Creating migration depends on docker

When I tried to create migration without starting the server on docker, it throws the following error
image
I think creating migration should not depend on whether the server is started or not and more importantly it's started on docker or not.

Unify logger

Thank for the great template, but a bit inconsistent with the logger, each module has use it own logger instead of lib.Logger

  • main app: zap
  • gorm: gorm logger
  • fx and viper may be unable to use the same logger

So can you make the gorm use lib.Logger for this template?

Add License

Hey all, wanted to reach out regarding a license for this template.

Currently, with no license it's by default "All right reserved" see sveltejs/template#78 and sveltejs/template#201 for more info on a similar situation - project with a public template on github and no license. Copy pasting from Svelte issue #78:

From the GitHub guidance on licensing:

You're under no obligation to choose a license. However, without a license, the default copyright laws apply, meaning that you retain all rights to your source code and no one may reproduce, distribute, or create derivative works from your work. If you're creating an open source project, we strongly encourage you to include an open source license. The Open Source Guide provides additional guidance on choosing the correct license for your project.

If you don't want to restrict things you can Use the 0BSD license - https://opensource.org/licenses/0BSD, alternatively you can go the path of Gorm and Gin, which both use the MIT license - https://opensource.org/licenses/MIT. These are just suggestions, of course, and the decision is ultimately up to you

Created #32 for 0BSD and #33 for MIT License. Feel free to merge either of them if you like those choices

Make folder structure modular.

Modular Folder Structures

Currently, routes, services, repository, etc have been added in their separate folders.
This make it less modular, harder to re-use and less maintainability.

Thinking of making this structure something like this;

pkg
  |-- authentication (model, handler, service, route, repository, serializer etc.)
  |-- users
  |-- .... 
  |-- common (some common things re-usable by multiple modules)
internal
  |-- framework's internal wiring code 
domain
  |-- users.go (interfaces for users package)
  |-- authentication.go (interfaces for authentication package)

While we are at it, we need to look at the go's recommended folder structure for packages.
Following something like this

Failed migration command: make create

Error after executing migration make create

What is the name of migration?test
/bin/sh: 2: migrate: not found
Makefile:20: recipe for target 'create' failed
make: *** [create] Error 127

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.