scaffold

command module
v1.19.22 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 24, 2025 License: MIT Imports: 1 Imported by: 1

README

scaffold

Note: If you are reading this on Github, please note that the repo has moved to Gitlab (gitlab.com/golang-utils/scaffold) and this is only a mirror.

scaffolding via go templates

Installation

git clone gitlab.com/golang-utils/scaffold
cd cmd/scaffold
go install .

Usage

given the following template (file models.templ)

{
    "Models": [
        {   "Name": "",
            "Fields": [ {"Name": "", "Type": ""} ] }
    ]
}

{{range .Models}}
>>>models/{{toLower .Name}}/
>>>model.go
package {{replace .Name "_" "."}}

type {{camelCase1 .Name}} struct {{curlyOpen}}
{{range .Fields}}	{{camelCase1 .Name}} {{.Type}}
{{end}}{{curlyClose}}
<<<model.go
<<<models/{{toLower .Name}}/
{{end}}

and the following json (file models.json)

{
    "Models": [
        {
            "Name": "person",
            "Fields": [
                {"Name": "first_name","Type": "string"},
                {"Name": "last_name" ,"Type": "string"}
            ]
        },
        {
            "Name": "address",
            "Fields": [
                {"Name": "street_no","Type": "string"},
                {"Name": "city","Type": "string"}
            ]
        }
    ]
}

when running the command

scaffold -t=models.templ < models.json

the following directory structure would be build:

models
├── address
│   └── model.go
└── person
    └── model.go

where models/address/model.go contains

package address

type Address struct {
    StreetNo string
    City string
}

and models/person/model.go contains

package person

type Person struct {
    FirstName string
    LastName string
}

To help generating a template from an existing file structure, make sure, you just have one item per collection and then run

scaffold scan --scandir=your/dir

and edit your template as you need.

Documentation

https://pkg.go.dev/gitlab.com/golang-utils/scaffold

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis
cmd
scaffold module
lib
scaffold
Package scaffold provides file and directory generation based on templates.
Package scaffold provides file and directory generation based on templates.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL