gig

module
v1.2.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 16, 2023 License: MIT

README ΒΆ

gig

πŸš€ Command line interface which provides a number helpful command to assist Go project development!

⚑️ Getting started

First, download and install Go. Then install gig by using go install command

go install github.com/awgst/gig/cmd/gig@latest

Check if gig is installed successfully

gig

Create a new project

gig create <project-name>

and it will create a new project with the following structure

.
β”œβ”€β”€ cmd
β”‚   └── seeder
β”‚   β”‚   └── main.go
β”‚   └── main.go
β”œβ”€β”€ database
β”‚   └── migrations
β”‚   β”‚   └── 20210101000000_create_users_table.go
β”‚   └── seeder
β”‚   β”‚   └── seeder.go
β”œβ”€β”€ pkg
β”‚   └── common
β”‚   └── database
β”‚   └── env
β”‚   └── router
β”‚   └── ...
β”œβ”€β”€ src
β”‚   └── app
β”‚   └── config
β”‚   └── routes
β”œβ”€β”€ .env.example
β”œβ”€β”€ .gitignore
β”œβ”€β”€ Dockerfile
β”œβ”€β”€ docker-compose.yml
β”œβ”€β”€ gig.json
β”œβ”€β”€ go.mod
β”œβ”€β”€ go.sum

Set up the .env file based on the .env.example file, then you can run the project

go run cmd/main.go

or you can use the up command if you want to run the project with docker. It will run docker-compose up command

gig up

Notes: make sure you have docker installed on your machine

create your first module

gig make:module <name>

It will create a new module inside the src/app directory with the following structure

.
β”œβ”€β”€ http
β”‚   └── handler
β”œβ”€β”€ model
β”œβ”€β”€ repository
β”œβ”€β”€ service
β”œβ”€β”€ module-name.go

*Handler is a place where you can put your handler function.
*Model is a place where you can put your model struct.
*Repository is a place where you can put your repository function.
*Service is a place where you can put your service function.
*module-name.go is a place where you will create instance of handler, service and repository of your module.

If you prefered to use GORM on the first installation (you can disable it later on gig.json configuration), please to uncomment the following line in the ./pkg/database/gorm.go file based on your database

// Dialector for open connection based on driver
// Uncomment the code based on your database driver
// Run go get gorm.io/driver/{driver_name} to install the driver
// Example: go get gorm.io/driver/mysql and import "gorm.io/driver/mysql"
var dialectors = func(driver, dsn string) gorm.Dialector {
	return map[string]gorm.Dialector{
		// "mysql":      mysql.Open(dsn),
		// "postgres": postgres.Open(dsn),
	}[driver]
}

πŸ“š Usage

create

Create a new project

gig create <name>

Arguments:

Argument Description Type Required?
name The name of the project string Yes

Flags:

Option Description Type Default Required?
--version Set the specific Go version. string 1.20 No

make

Make file

gig make:<type> <module_name>

Arguments:

Argument Description Type Required?
module_name The name of the project string Yes

Types:

Type Description
migration Create a new migration
module Create a new module
handler Create a new handler
model Create a new model
repository Create a new repository
service Create a new service
request Create a new request
response Create a new response

up

Run docker-compose up command

gig up

migrate

Run a simple database migration. Under the hood it used golang-migrate/migrate for managing database migration

gig migrate <command>

Commands:

Command Description
up Run migrate
down Rollback migrate

To see the list of available commands, use the --help flag

gig --help

πŸ“ License

This project is licensed under the MIT License

Directories ΒΆ

Path Synopsis
cmd
Package cmd implements the list of commands that can be executed
Package cmd implements the list of commands that can be executed
gig
make
Package make implements the command to generate a new file
Package make implements the command to generate a new file
migrate
Package make implements the command to migrate files with suffix `.down.sql` and `.down.sql`
Package make implements the command to migrate files with suffix `.down.sql` and `.down.sql`
pkg
Package pkg implements list function and variable that can be used by other packages
Package pkg implements list function and variable that can be used by other packages
generate
Package generate implements of generate files for command needs
Package generate implements of generate files for command needs
template

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL