App Structure :
- app -> all logic of application requirement
- controllers -> controller to consume on route
- dto_request -> data transfer object request
- dto_response -> data transfer object response
- middleware -> middleware of the app
- models -> model of database
- repositories -> repository to encapsulation query or fetch data
- services -> to build logic of the app
- ucase -> to build specific logic and generate response formatted to consume by route
- config -> configuration app
- pkg -> package usage in app
- provider -> behavior app needed
- route -> app route (api/web)
- Run HTTP server
example :
<your-app> http serve
my_app http server
- Run HTTP server on Development/Local Machine
go run main.go http serve
Get and install tools from github repo
go install github.com/dienggo/diego/cmd/[email protected]
Check your GOPATH location, windows -> skip this step
go env GOPATH
$ <your-location-gopath>
Copy path and make alias installed diego, example on macos with zsh
alias diego="/<your-location-gopath>/bin/diego"
Example :
alias diego="/usr/development/go/bin/diego"
Use diego
diego -h
Update Diego (beta - available at version >= v1.2.0)
diego update
-
awesome_project -> your project name & module
diego build awesome_project
-
example_case -> your controller & controller stored to
diego generate controller example_case
app/controllers/example_case.go
-
generate all template of
use case
[delete.go][detail.go][list.go][upsert.go]exampleCase -> yourdiego generate ucase example
use case
&use case
stored toapp/ucase/exampleCase
-
custom -> your
diego generate ucase custom exampleCase
use case
&use case
stored toapp/ucase/exampleCase/custom.go
-
example_case -> your service & service stored to
diego generate service example_case
app/services/example_case.go
-
example_case -> your middleware & middleware stored to
diego generate service example_case
app/middleware/example_case.go
-
example_case -> your command & command stored to
diego generate cmd example_case
cmd/example_case.go
& also registered on provider/cmd.go automatically.
run your command on development/local :example :go run main.go <your-command-name-or-alias>
go run main.go my-command
Cause this framework depends on goose
, install goose
first ---> https://github.com/pressly/goose
- Get help usage
diego migration -h
- Migrate the DB to the most recent version available
diego migration up
- Migrate the DB up by 1
diego migration up-by-one
- Migrate the DB to a specific VERSION
diego migration up-to VERSION
- Roll back the version by 1
diego migration down
- Roll back to a specific VERSION
example :
diego migration down-to VERSION
migration down-to 123
- Re-run the latest migration
diego migration redo
- Roll back all migrations
diego migration reset
- Dump the migration status for the current DB
diego migration status
- Print the current version of the database
diego migration version
- Creates new migration file with the current timestamp
example :
diego migration create NAME [sql|go]
diego migration create your_table sql
- Apply sequential ordering to migrations
diego migration fix
- Check migration files without running them
diego migration validate
github.com/go-playground/validator/v10 v10.11.1
github.com/google/uuid v1.3.0
github.com/gorilla/mux v1.8.0
github.com/gorilla/schema v1.2.0
github.com/joho/godotenv v1.4.0
github.com/sirupsen/logrus v1.9.3
github.com/stretchr/testify v1.8.2
github.com/urfave/cli/v2 v2.25.7
golang.org/x/text v0.8.0
gopkg.in/yaml.v2 v2.4.0
gorm.io/driver/mysql v1.3.4
gorm.io/gorm v1.23.7