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:

  1. Update .env with your configuration
  2. Modify app.controller.go for your endpoints
  3. Add modules with goose g module
  4. Configure database if needed

Next Steps