Skip to content
Levy Araújo Sampaio edited this page Jun 5, 2024 · 2 revisions

General explanation

Our cli has two main funcionalities:

  • Generate and destroy code
  • Manage migrations and database

Code generation

The code generation funcionality create two routes types

  1. CRUD
  2. USECASE

CRUD

The crud command generate:

  • routes and handlers on cmd/http folder
  • domain with ID field on internal/aplication/domain
  • service for each route with a type for request, response and a service file for your business rules
  • repository based on your domain for mysql database comunication

Command example for users crud:

go run cmd/cli/main.go create-domain users

USECASE

The usecase command generate:

  • single route and handler without any dependecy injection
  • service with a type for request, response and a service file for your business rules

Command example for user login usecase:

go run cmd/cli/main.go create-domain user_login --type=usecase

Migrator

The migrator is based on atlas: https://atlasgo.io/getting-started If you want can use atlas for manage your database without use the cli

The migrator has 3 commands:

  1. migrate
  2. inspect
  3. generate

Migrate

this command read the tools/migrator/schema/schema.my.hcl file and migrate for the real database connceted with env configuration

Command example for migration:

/app # go run cmd/cli/main.go migrate 
Applied 2 changes:
CREATE TABLE `dummies` (
  `id` char(26) NOT NULL,
  `name` char(255) NOT NULL,
  PRIMARY KEY (`id`)
) CHARSET utf8mb4 COLLATE utf8mb4_0900_ai_ci
CREATE TABLE `report_routes` (
  `id` char(26) NOT NULL,
  PRIMARY KEY (`id`)
) CHARSET utf8mb4 COLLATE utf8mb4_0900_ai_ci

Inspect

this command read the connceted database and print on console a hcl with this configuration

example:

go run cmd/cli/main.go inspect

Generate

Similar to inspect but generate a hcl file on tools/migrator/generated, if you want to use the generated hcl on zord migrations just replace tools/migrator/schema/schema.my.hcl with this file content

example:

go run cmd/cli/main.go generate
Clone this wiki locally