Skip to content

goca template ​

Manage custom templates for personalized code generation.

Syntax ​

bash
goca template [subcommand]

Description ​

The goca template command provides tools to initialize and manage custom templates for code generation. Custom templates allow you to override Goca's built-in templates with project-specific patterns.

Customization

Custom templates let you enforce your team's coding style across all generated code while keeping the benefits of automated generation.

Subcommands ​

init ​

Initialize the custom templates directory with default templates that you can customize.

bash
goca template init

Creates a .goca/templates/ directory with editable templates for all layers:

  • Entity templates
  • Use case templates
  • Repository templates
  • Handler templates
  • DI container templates

After initialization, Goca will automatically use your custom templates when generating code.

list ​

List all available custom templates in the current project.

bash
goca template list

Displays the templates directory path and confirms whether templates exist.

Usage Examples ​

Set up custom templates ​

bash
# Initialize templates
goca template init

# Edit to match your style
# Templates are in .goca/templates/

Check available templates ​

bash
goca template list

Template Functions ​

Custom templates have access to these template functions:

FunctionDescriptionExample
{{pascal .EntityName}}PascalCaseUserProfile
{{snake .EntityName}}snake_caseuser_profile
{{camel .EntityName}}camelCaseuserProfile
{{lower .EntityName}}lowercaseuserprofile
{{plural .EntityName}}PluralizedUsers

Template Data ​

Templates receive a TemplateData struct with these fields:

FieldTypeDescription
EntityNamestringEntity name (PascalCase)
ModulestringGo module path
DatabasestringDatabase type
Fields[]FieldParsed field definitions
HasValidationboolWhether validation is enabled

Released under the MIT License.