Documentation ¶
Index ¶
- Constants
- Variables
- func Check(err error)
- func EnvDollar() string
- func EnvGoArch() string
- func EnvGoFile() string
- func EnvGoLine() int
- func EnvGoOS() string
- func EnvGoPackage() string
- func EnvGoRoot() string
- func EnvOrDefault(key, def string) string
- func EnvOrDefaultInt(key string, def int) int
- func EnvPath() string
- func Exec[T Template, D any](tmpl T, d D, startTemplate string) ([]byte, error)
- func ExecTemplate[T Template, D any](tmpl T, dot D, name string) []byte
- func Generate[T Template, D any](tmpl T, dot D, name, out string)
- func GoFmt(src []byte) (dst []byte, err error)
- func GoFmtReader(r io.Reader) ([]byte, error)
- func IfStringEmptyUseDefault(s, def string) string
- func Must[T any](t T, err error) T
- func NewTemplate[T Template](templates fs.FS, funcs map[string]any) T
- func OutputFilename(original string) string
- func TestOutputFilename(original string) string
- func UnmarshalYAML[T any](filename string) (v T, err error)
- type Template
Constants ¶
const ( EnvKeyGoArch = "GOARCH" EnvKeyGoOS = "GOOS" EnvKeyGoFile = "GOFILE" EnvKeyGoLine = "GOLINE" EnvKeyGoPackage = "GOPACKAGE" EnvKeyGoRoot = "GOROOT" EnvKeyDollar = "DOLLAR" EnvKeyPath = "PATH" )
Variables ¶
var ( EnvDefaultGoPackage = "generator_helpers" EnvDefaultGoFile = "" EnvDefaultGoArch = runtime.GOARCH EnvDefaultGoOS = runtime.GOOS EnvDefaultGoLine = 0 EnvDefaultDollar = "$" EnvDefaultPath = os.Getenv(EnvKeyPath) EnvDefaultGoRoot = os.Getenv(EnvKeyGoRoot) )
Functions ¶
func Check ¶
func Check(err error)
Check takes an error as an argument. If the error is not nil, it logs the error and exits the program.
func EnvDollar ¶
func EnvDollar() string
EnvDollar returns the dollar sign from environment or default.
func EnvGoArch ¶
func EnvGoArch() string
EnvGoArch returns the Go architecture from environment or default.
func EnvGoFile ¶
func EnvGoFile() string
EnvGoFile returns the Go file name from environment or default.
func EnvGoLine ¶
func EnvGoLine() int
EnvGoLine returns the Go file line number from environment or default.
func EnvGoOS ¶
func EnvGoOS() string
EnvGoOS returns the Go operating system from environment or default.
func EnvGoPackage ¶
func EnvGoPackage() string
EnvGoPackage returns the Go package name from environment or default.
func EnvGoRoot ¶
func EnvGoRoot() string
EnvGoRoot returns the Go file root path from environment or default.
func EnvOrDefault ¶
EnvOrDefault returns the environment variable's value or default if empty.
func EnvOrDefaultInt ¶
EnvOrDefaultInt returns the environment variable's integer value or default if empty. If there is an error parsing the environment variable. The default will be returned.
func ExecTemplate ¶
ExecTemplate executes a template and returns the generated content as a byte slice. It assumes the output is go source code and formats the output.
func GoFmt ¶
GoFmt formats Go source code, returning the formatted code or the original and an error.
func GoFmtReader ¶
GoFmtReader functions similarly to GoFmt but accepts an io.Reader as input. It reads the source code from the reader, formats it, and returns the formatted code and any error encountered.
func IfStringEmptyUseDefault ¶
IfStringEmptyUseDefault returns the default value if the string is empty.
func Must ¶
Must takes a value and an error. If the error is not nil, it logs the error and exits the program. Otherwise, it returns the value.
func NewTemplate ¶
NewTemplate initializes a new template, either text or HTML, with provided functions and file system.
func OutputFilename ¶
OutputFilename generates a filename for the output file by appending "_generated" to the original file name.
func TestOutputFilename ¶
TestOutputFilename generates a filename for the test output file by appending "_test" to the original file name.
func UnmarshalYAML ¶
UnmarshalYAML reads YAML data from a file and unmarshals it into a value. It returns the unmarshaled value and any error encountered.