generate

package
v0.0.0-...-19db756 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 22, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Generate

func Generate(opts ...GenerateOption) ([]byte, error)

Generate parses one or more config files and produces Go source code with a typed struct. The struct fields include env, yaml, json, and toml tags inferred from the config structure, plus default value tags.

output, err := generate.Generate(
    generate.WithInput("config.yaml"),
    generate.WithStructName("AppConfig"),
    generate.WithPackage("config"),
)
os.WriteFile("config.go", output, 0644)

Types

type GenerateOption

type GenerateOption func(*genConfig)

GenerateOption configures the code generation process. Use the With* functions to create options.

func WithDefaultTag

func WithDefaultTag(enabled bool) GenerateOption

WithDefaultTag controls whether default value tags are generated. Default is true.

func WithEnvTag

func WithEnvTag(enabled bool) GenerateOption

WithEnvTag controls whether env struct tags are generated. Default is true.

func WithInput

func WithInput(path string) GenerateOption

WithInput sets the input config file path. Exactly one of WithInput or WithInputPaths must be provided.

func WithInputPaths

func WithInputPaths(paths ...string) GenerateOption

WithInputPaths sets multiple input config files to merge. Exactly one of WithInput or WithInputPaths must be provided.

func WithJSONTag

func WithJSONTag(enabled bool) GenerateOption

WithJSONTag controls whether json struct tags are generated. Default is true.

func WithOutputDir

func WithOutputDir(dir string) GenerateOption

WithOutputDir sets the output directory for the generated file. Defaults to ".".

func WithOutputFile

func WithOutputFile(name string) GenerateOption

WithOutputFile sets the output file name. Defaults to "<struct_snake>.go".

func WithPackage

func WithPackage(name string) GenerateOption

WithPackage sets the Go package name for the generated file. If not provided, the package name is inferred from the output directory name.

func WithStructName

func WithStructName(name string) GenerateOption

WithStructName sets the name of the generated Go struct. Defaults to "Config".

func WithTOMLTag

func WithTOMLTag(enabled bool) GenerateOption

WithTOMLTag controls whether toml struct tags are generated. Default is true.

func WithYAMLTag

func WithYAMLTag(enabled bool) GenerateOption

WithYAMLTag controls whether yaml struct tags are generated. Default is true.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL