π 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
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