This package provides Go structures for constructs used in Go source code and a helper to write those constructs to .go
file with valid syntax.
-
Get the package
go get github.com/xapi-tools/gocodegen@latest
-
Create Go structures for intended source code and generate file
package main import gcg "github.com/xapi-tools/gocodegen" func main() { gw := gcg.NewGoFileWriter() gw.ToFile("./test.go") }
Check following for more comprehensive examples: