Skip to content
/ gojira Public

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

License

Notifications You must be signed in to change notification settings

illud/gojira

Repository files navigation

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.

About

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

Topics

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages