Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/illud/gojira
Gojira is a cli tool to create clean architecture app for you including gin-gonic, bcrypt and jwt.
https://github.com/illud/gojira
bcrypt clean-architecture gin gin-gonic go golang gorm jwt mysql prisma prisma-client prisma-client-go
Last synced: 30 days ago
JSON representation
Gojira is a cli tool to create clean architecture app for you including gin-gonic, bcrypt and jwt.
- Host: GitHub
- URL: https://github.com/illud/gojira
- Owner: illud
- License: mit
- Created: 2021-06-19T05:14:47.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2023-08-18T23:27:26.000Z (about 1 year ago)
- Last Synced: 2024-10-02T05:23:12.474Z (about 1 month ago)
- Topics: bcrypt, clean-architecture, gin, gin-gonic, go, golang, gorm, jwt, mysql, prisma, prisma-client, prisma-client-go
- Language: Go
- Homepage:
- Size: 88.9 KB
- Stars: 8
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# Gojira
![](https://raw.githubusercontent.com/illud/eskolvar.github.io/main/assets/img/gojira.png)
[![Test Status](https://github.com/illud/gojira/actions/workflows/go.yml/badge.svg)](https://github.com/illud/gojira/actions/workflows/go.yml/badge.svg)
[![GoDoc](https://pkg.go.dev/badge/github.com/illud/gojira?status.svg)](https://pkg.go.dev/github.com/illud/gojira?tab=doc)
[![Go Report Card](https://goreportcard.com/badge/github.com/illud/gojira)](https://goreportcard.com/report/github.com/illud/gojira)
## 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
- Clean Architecture Folder Structure (https://blog.cleancoder.com/uncle-bob/2012/08/13/the-clean-architecture.html)
- Gin Gonic (https://github.com/gin-gonic/gin)
- [Swagger](#swagger) (https://github.com/swaggo/gin-swagger)
- Jwt (https://github.com/dgrijalva/jwt-go)
- Bcrypt (https://golang.org/x/crypto/bcrypt)
- [Async](#async) - Async functions
- Auto add swagger for your endpoint
- [Modules](#modules) - Auto generate module with crud flow
- [Database Service](#database-service) - Auto generate db service client
- Mysql
- Gorm
- Prisma
- Example tasks api
- [Testing](#testing) (Auto generate test example when creating a new modules)## Installation
Gojira requires [Go](https://golang.org/) v1.11+ to run.
Install the dependencies.
```sh
go get github.com/illud/gojira
```
Or```sh
go install github.com/illud/gojira@latest
```
## How to useIn your terminal type to see all avaible commands:
```sh
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 serviceEnter 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 serviceEnter 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 serviceEnter 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:
```go
db "github.com/yourProjectName/infraestructure/databases"
```Example for Mysql:
```go
// 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:
```go
// 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:
```go
dbClient "github.com/yourProjectName/infraestructure/databases"
"github.com/yourProjectName/infraestructure/databases/prisma/db"
```
Example for prisma:
```go
// 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:```go
package mainimport 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
```shell
swag init
```
To learn more visit (https://github.com/swaggo/gin-swagger)
# Testing
To run tests use
```go
go test -v ./...
```
To get coverage
```go
go test -v -cover --coverprofile=coverage.out -coverpkg=./... ./...
```
To view test coverage on your browser
```go
go tool cover -html=coverage.out
```
Total coverageWindows
```go
go tool cover -func=coverage.out | findstr total:
```
Linux
```go
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
``````mermaid
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]
```## License
MIT
Gojira is [MIT licensed](LICENSE).