Jdsleppy / genplate

File generation using golang templates

Home Page:https://golang.org/pkg/text/template/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

genplate

File generation with golang templates https://golang.org/pkg/text/template/

genplate -- file generation with golang templates
USAGE:

        genplate template_file out_file data_file

template_file    relative path to a golang template file
out_file         relative path to the output, which will be truncated
data_file        relative path to a JSON file to be passed in as template data

Installation

$ go get github.com/Jdsleppy/genplate

Examples

Full examples here

go generate example

genplate/examples/generate.go

package examples

//go:generate genplate example.template generatedcowboy.go cowboylingo.json
//go:generate genplate example.template generatedrobot.go robotlingo.json

genplate/examples/cowboylingo.json

{
    "FuncName": "CowboyLingo",
    "PrintVals": [
        "YeeHaw",
        "howdyPartner",
        "goodbye_buddy"
    ]
}
$ cd genplate
$ go generate ./...
# generatedcowboy.go and generatedrobot.go now exist

Command line example

$ cd genplate/examples
$ genplate example.template generatedcowboy.go cowboylingo.json
# generatedcowboy.go now exists

Built-in template funcs

Add your custom funcs to a fork, or open a PR if they are sufficiently generic.

  • Pluralize
  • CamelCase
  • PascalCase
  • SnakeCase

About

File generation using golang templates

https://golang.org/pkg/text/template/

License:MIT License


Languages

Language:Go 100.0%