Creating Applications
Use the Goose CLI to scaffold new applications with proper structure and boilerplate.
Basic Usage
goose app --name=<app-name> --template=<template>
Available Templates
API Template
Create a RESTful API application:
goose app --name=myapi --template=api
Generated structure:
myapi/
โโโ .env # Environment configuration
โโโ go.mod # Go module file
โโโ main.go # Application entry point
โโโ app/
โโโ app.module.go # Root module
โโโ app.controller.go # Main controller
โโโ app.service.go # Main service
โโโ app.routes.go # Route definitions
โโโ app.dtos.go # Data transfer objects
โโโ jobs/ # Background jobs
โ โโโ sample.job.go
โโโ queries/ # Database queries
โโโ sample.query.go
Features included:
- JSON API server
- Database support (SQLite default)
- Background job examples
- Query examples
Web Template
Create a server-rendered web application:
goose app --name=myweb --template=web
Generated structure:
myweb/
โโโ .env
โโโ go.mod
โโโ main.go
โโโ app/
โโโ app.module.go
โโโ app.controller.go
โโโ app.service.go
โโโ app.routes.go
โโโ app.dtos.go
โโโ templates/ # HTML templates
โโโ base/
โ โโโ layout.html
โโโ pages/
โ โโโ home.html
โโโ partials/
โโโ header.html
โโโ footer.html
Features included:
- HTML template rendering
- Layout system
- Partial templates
- Static file serving
CLI Template
Create a command-line application:
goose app --name=mycli --template=cli
Generated structure:
mycli/
โโโ .env
โโโ go.mod
โโโ main.go
โโโ app/
โโโ app.module.go
โโโ app.controller.go
โโโ app.service.go
โโโ app.routes.go # Command definitions
โโโ app.dtos.go
Features included:
- Command routing
- Argument parsing
- Console output
Multi-Platform Template
Create an application with API, Web, and CLI:
goose app --name=mymulti --template=multi
Generated structure:
mymulti/
โโโ .env
โโโ go.mod
โโโ main.go
โโโ app/
โโโ api/ # API platform
โ โโโ api.module.go
โ โโโ api.controller.go
โ โโโ api.routes.go
โ โโโ api.service.go
โโโ web/ # Web platform
โ โโโ web.module.go
โ โโโ web.controller.go
โ โโโ web.routes.go
โ โโโ web.service.go
โ โโโ templates/
โโโ cli/ # CLI platform
โ โโโ cli.module.go
โ โโโ cli.controller.go
โ โโโ cli.routes.go
โ โโโ cli.service.go
โโโ shared/ # Shared code
โโโ shared.module.go
โโโ shared.service.go
โโโ entities/
Command Options
goose app --name=<name> --template=<template> [--path=<directory>]
| Flag | Description | Required | Default |
|---|---|---|---|
--name |
Application name | Yes | - |
--template |
Template type | Yes | - |
--path |
Output directory | No | Current directory |
Examples
# Create in current directory
goose app --name=myapi --template=api
# Create in specific directory
goose app --name=myapi --template=api --path=/home/user/projects
# Create web app
goose app --name=blog --template=web
# Create CLI tool
goose app --name=tools --template=cli
# Create multi-platform app
goose app --name=platform --template=multi
After Creating
1. Navigate to Project
cd myapi
2. Install Dependencies
go mod tidy
3. Configure Environment
Edit .env file:
APP_NAME=myapi
APP_ENV=development
HOST=localhost
PORT=8080
4. Run the Application
go run main.go
5. Test It
API:
curl http://localhost:8080/
Web:
Open http://localhost:3000 in browser
CLI:
go run main.go cli <command>
Generated Code Overview
main.go (API Template)
package main
import (
"myapi/app"
"github.com/awesome-goose/goose"
"github.com/awesome-goose/goose/platforms/api"
)
func main() {
platform := api.NewPlatform(
api.WithHost("localhost"),
api.WithPort(8080),
)
module := &app.AppModule{}
stop, err := goose.Start(goose.API(platform, module, nil))
if err != nil {
panic(err)
}
defer stop()
}
app.module.go
package app
import "github.com/awesome-goose/goose/types"
type AppModule struct{}
func (m *AppModule) Imports() []types.Module {
return []types.Module{}
}
func (m *AppModule) Exports() []any {
return []any{}
}
func (m *AppModule) Declarations() []any {
return []any{
&AppController{},
&AppService{},
}
}
Customizing Templates
After scaffolding, customize:
- Update
.envwith your configuration - Modify
app.controller.gofor your endpoints - Add modules with
goose g module - Configure database if needed
Next Steps
- Generating Modules - Add features
- Directory Structure - Understand layout
- Quick Start - Build your first feature