Skip to content

kukymbr/go-generator-template

Repository files navigation

Golang code generator app template

This is a generator to generate generators generating the code 🍪 cookiecutter ✂️ template for a Golang code generator app project.

Creating a new project

First, clone this repository and change into its directory:

git clone https://github.com/kukymbr/go-generator-template.git
cd go-generator-template

create.sh

The create.sh file is a script to create a new project using the skeleton template. Docker engine is required.

Usage: create.sh <project_name> [--target=<target_dir>] [--tag=<image_tag>] [EXTRA_ARGS]

  project_name: name of the project to generate, required
  --target: path to the target projects' dir, default is "./gen"
  --tag: docker image tag to build with, default is "apisrv_skeleton_cookiecutter"
  EXTRA_ARGS: additional arguments to pass to the cookiecutter

You are free to run this script without any cookiecutter arguments; in this case, the interactive mode of the cookiecutter will be executed:

./create.sh your_app_fancy_name

To run cookiecutter in non-interactive mode, pass --no-input argument and template values to override to the EXTRA_ARGS, for example:

./create.sh your_app_fancy_name --no-input go_version=1.25

Local installation

The create.sh script uses Docker images to run cookiecutter. If you want to avoid the Docker usage, install the cookiecutter locally.

Follow the official documentation steps to install a cookiecutter, then run it against this dir. The __project_name is a mandatory argument:

# Running in interactive mode:
cookiecutter --verbose --output-dir ~/path/to/projects/dir __project_name=testapp .

# Running in non-interactive mode with specified template values:
cookiecutter --verbose --output-dir ~/path/to/projects/dir --no-input __project_name=testapp go_version=1.25 . 

In the case of the local cookiecutter execution, the postintall.sh script is needed to be executed when project dir is ready:

cd ~/path/to/projects/dir/testapp 
./postintall.sh

It could be deleted after the execution.

Available template options

See the cookiecutter.json for available options.

About

🍪✂️ Cookiecutter template for a Golang code generators

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published