An open API service indexing awesome lists of open source software.

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.

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.
```