Ginboot CLI is a powerful command-line tool for creating and managing Ginboot framework projects. It provides a streamlined way to scaffold new projects, build applications, and deploy to AWS Lambda.
go install github.com/klass-lk/ginboot-cli@latest
- Go 1.21 or later
- AWS SAM CLI (for deployment)
- AWS credentials configured
Create a new Ginboot project with a standard directory structure:
ginboot new myproject
This will create a new project with the following structure:
myproject/
├── internal/
│ ├── controller/
│ │ └── user_controller.go
│ ├── model/
│ │ └── user.go
│ ├── repository/
│ │ └── user_repository.go
│ └── service/
│ └── user_service.go
├── main.go
├── go.mod
├── Makefile
└── template.yaml
Build your project using AWS SAM:
cd myproject
ginboot build
The build process will:
- Compile your Go application
- Create a deployment package
- Store build artifacts in
.aws-sam/build/
The project includes Docker and docker-compose configurations for easy deployment:
- Build and run with docker-compose:
docker-compose up --build
This will:
- Build the Go application
- Start a MongoDB container
- Create a Docker network
- Set up volume for MongoDB data persistence
- Expose the API on port 8080
- Access your API at
http://localhost:8080/api/v1
To run in detached mode:
docker-compose up -d
To stop the services:
docker-compose down
Deploy your application to AWS Lambda:
ginboot deploy
On first run, you'll be prompted for:
- Stack name (defaults to project name)
- AWS Region (defaults to us-east-1)
- S3 bucket configuration (can use SAM's default bucket)
These settings will be saved in ginboot-app.yml
for future deployments.
Controllers handle HTTP requests and define API endpoints. Example:
func (c *UserController) Register(group *ginboot.ControllerGroup) {
group.GET("/:id", c.GetUser)
group.POST("", c.CreateUser)
}
Models define your data structures and MongoDB document mappings:
type User struct {
ID string `json:"id"`
Username string `json:"username"`
Email string `json:"email"`
}
Repositories handle database operations using Ginboot's MongoDB integration:
ty
718D
pe UserRepository struct {
*ginboot.MongoRepository[model.User]
}
Services contain your business logic:
type UserService interface {
GetUser(id string) (model.User, error)
CreateUser(user model.User) error
}
Deployment configuration is stored in ginboot-app.yml
:
stack_name: myproject
region: us-east-1
use_default_bucket: true
AWS SAM template defining your Lambda function and API Gateway:
Resources:
MyProjectFunction:
Type: AWS::Serverless::Function
Properties:
Handler: bootstrap
Runtime: provided.al2
Events:
ApiEvents:
Type: Api
Properties:
Path: /{proxy+}
Method: ANY
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License - see the LICENSE file for details.