https://github.com/fluhus/goat
Easily generate golang source from templates.
https://github.com/fluhus/goat
code-generation code-generator go goats golang templates
Last synced: 5 months ago
JSON representation
Easily generate golang source from templates.
- Host: GitHub
- URL: https://github.com/fluhus/goat
- Owner: fluhus
- License: mit
- Created: 2021-01-25T08:01:21.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2025-03-19T20:35:33.000Z (about 1 year ago)
- Last Synced: 2025-03-19T21:38:43.623Z (about 1 year ago)
- Topics: code-generation, code-generator, go, goats, golang, templates
- Language: Go
- Homepage:
- Size: 12.7 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Goat
```
go get github.com/fluhus/goat
```
Goat (short for go-templates) allows one to easily generate golang source from templates using `go generate`.
## Example
mypackage.go
```go
package mypackage
//go:generate goat -i types.got -o types.go -d [8,16,32,64]
// ...
```
types.got
```go
package mypackage
{{range . -}}
type counter{{.}} map[int{{.}}]int
{{end}}
```
types.go (output)
```go
// ***** DO NOT EDIT THIS FILE MANUALLY. *****
//
// This file was auto-generated using goat.
//
// goat: https://www.github.com/fluhus/goat
package mypackage
type counter8 map[int8]int
type counter16 map[int16]int
type counter32 map[int32]int
type counter64 map[int64]int
```
## Usage
```
go run github.com/fluhus/goat [-i INPUT_FILE] [-o OUTPUT_FILE] [-d DATA] [-nh] [-nf]
-d string
JSON-encoded data for the template.
-i string
Path to input template file. If omitted, reads from stdin.
-nf
Don't run gofmt on the result.
-nh
Don't add a header to the output file.
-o string
Path to output go file. If omitted, writes to stdout.
```