Giter Club home page Giter Club logo

gojira's Introduction

Gojira

Test Status GoDoc Go Report Card

Create project with Clean Architecture folder structure


Gojira is a cli tool to create clean architecture app for you including gin-gonic, bcrypt and jwt.

  • Creates Clean Architecture project for you

Features

Installation

Gojira requires Go v1.11+ to run.

Install the dependencies.

go get github.com/illud/gojira

Or

go install github.com/illud/gojira@latest

How to use

In your terminal type to see all avaible commands:

gojira

To create a new gin-gonic with clean architecture project(This includes a crud example with the name of Tasks):

[x] New project
[ ] Module
[ ] Module with crud
[ ] DB service

Enter Project Name: yourprojectname

Modules

To create a new module with simple example flow: please use snake_case when the module name consist of two or more words

[ ] New project
[x] Module
[ ] Module with crud
[ ] DB service

Enter Module Name: your_module_name

To create a new module with crud flow: please use snake_case when the module name consist of two or more words

[ ] New project
[ ] Module
[x] Module with crud
[ ] DB service

Enter Module Name: your_module_name

Database service

To create a new db service client with Mysql, Gorm or Prisma:

[ ] New project
[ ] Module
[ ] Module with crud
[x] DB service

Mysql - to learn more visit (https://github.com/go-sql-driver/mysql)

Enter DB(mysql, gorm or prisma) Name: mysql

Gorm - to learn more visit (https://github.com/jinzhu/gorm)

Enter DB(mysql, gorm or prisma) Name: gorm

Prisma - to learn more visit (https://github.com/prisma/prisma-client-go)

Enter DB(mysql, gorm or prisma) Name: prisma

This will generate a database connection in infraestructure/databases/client.go


For Mysql and Gorm import the service in your repository like for example:

db "github.com/yourProjectName/infraestructure/databases"

Example for Mysql:

// Insert new tasks
res, err := db.Client().Exec("INSERT INTO tasks VALUES(DEFAULT, 'Title', 'Desc')")
if err != nil {
  fmt.Println("ERROR: ", err)
}
fmt.Println(res)

To learn more visit (https://github.com/go-sql-driver/mysql)


Example for Gorm:

// Insert new tasks
err := db.Client().Save(&tasksEntity.Task{
  Title:       "TEST",
  Description: "This is a description",
})

if err != nil {
  fmt.Println(err)
}

To learn more visit (https://github.com/jinzhu/gorm)


For prisma import:

dbClient "github.com/yourProjectName/infraestructure/databases"
"github.com/yourProjectName/infraestructure/databases/prisma/db"

Example for prisma:

// Insert new tasks
createdTask, err := dbClient.Client().Tasks.CreateOne(
  db.Tasks.Title.Set("Hi from Prisma!"),
  db.Tasks.Description.Set("Prisma is a database toolkit and makes databases easy."),
).Exec(dbClient.Context)

if err != nil {
  fmt.Println(err)
}

result, _ := json.MarshalIndent(createdTask, "", "  ")
fmt.Printf("created task: %s\n", result)

To learn more visit (https://github.com/prisma/prisma-client-go)


Async

How to use async:

package main

import async "github.com/yourProjectName/utils/async"

//This functions wait 3 seconds to return 1
func DoneAsync() int {
	fmt.Println("Warming up ...")
	time.Sleep(3 * time.Second)
	fmt.Println("Done ...")
	return 1
}

func main() {
	fmt.Println("Let's start ...")

  //Here you call the function as async function
	future := async.Exec(func() interface{} {
		return DoneAsync()//The function that will await
	}).Await()

	fmt.Println("Done is running ...")
	fmt.Println(future)
}

Swagger

Build your application and after that, go to http://localhost:5000/swagger/index.html , you to see your Swagger UI.

When you create a new module swagger will be added automatically then you only need to modified what you need, but remember each time you modified swagger use the next command

swag init

To learn more visit (https://github.com/swaggo/gin-swagger)


Testing

To run tests use

go test -v ./...

To get coverage

go test -v -cover --coverprofile=coverage.out  -coverpkg=./... ./...

To view test coverage on your browser

go tool cover -html=coverage.out

Total coverage

Windows

go tool cover -func=coverage.out | findstr total:

Linux

go tool cover -func=coverage.out | grep total:

Folder Structure:


|-- controller
|        |      
|        |-tasks --> This is and example package(Create your own packages)
|            |       
|            |-tasks.controller.go --> This is and example controller file(Create your own controllers)
|            
|-- domain
|      |
|      |-usecase
|            |
|            |-tasks --> This is and example package(Create your own packages)
|                | 
|                |-task.usecase.go --> This is and example usecase file(Create your own usecases)
|
|-- infraestructure
|           |
|           |-databases
|           |      |
|           |      |-client.go
|           |
|           |-entities
|           |      |
|           |      |-tasks --> This is and example package(Create your own packages)
|           |          |
|           |          |-tasks.entity.go --> This is and example entity file(Create your own entity)
|           |
|           |-respository
|                  |
|                  |-tasks --> This is and example package(Create your own packages)
|                      | 
|                      |-tasks.repository.go --> This is and example repository file(Create your own repositories)
|                       
|-- utils
|       |
|       |-async
|       |    |
|       |    |-async.go
|       |
|       |-errors
|       |    |
|       |    |-errros.go
|       |
|       |-services
|               |
|               |-jwt
|               |   |
|               |   |-jwt.go
|               |
|               |-bcrypt
|                   |
|                   |-bcrypt.go
|
|-- env
|     |
|     |-env.go --> This is the env service
|
|
|-- routing
|       |
|       |-routing.go --> This is where all your routes lives
|
|
|-- test --> This is the test folder
|       |
|       |-tasks --> This is a test example folder
|       |   |
|       |   |-getTasks_test.go --> This is a test example file
|       |
|       |-other test folder --> your other test folder
flowchart TD
    C{Folder Structure}
    C -->|controller| D[task] -->N(task.go) 
    C -->|domain| E[usecase] -->Ñ(task) -->O(task.usecase.go) 
    C -->|infraestructure| F[databases]
    C -->|utils| G[databases]
    C -->|env| K[env.go]
    C -->|routing| L[routing.go]
    C -->|test| M[test.go]
Loading

License

MIT

Gojira is MIT licensed.

gojira's People

Contributors

illud avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  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.