{"modulePath":"github.com/cloudquery/codegen","version":"v0.4.1","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package structs\n\nPackage structs provides code generation utilities for optimizing Go struct types. The primary use case is flattening deeply nested API model structs into decode-efficient versions where nested struct fields are replaced with map\\[string]any, eliminating the decode -\u003e allocate -\u003e re-encode cycle that occurs when the CloudQuery SDK serializes nested fields as JSON columns.\n\n## Functions\n\n```go\nfunc Flatten(srcPath string, configs []StructConfig, outputDir string, opts ...Option) error\n```\nFlatten parses the Go source file at srcPath, finds the structs described by configs, replaces deeply nested struct fields with map\\[string]any, and writes generated files into outputDir.\n\nScalar types and string-based enum types are kept typed. All other types (structs, interfaces, cross-package types, maps) are flattened to map\\[string]any. Pointer wrappers are preserved for scalar types but collapsed for complex types.\n\n## Types\n\n```go\ntype Field struct {\n\tName    string\n\tType    string\n\tJSONTag string\n}\n```\nField represents a struct field in the generated output.\n\n```go\ntype Option func(*options)\n```\nOption configures the Flatten generator.\n\n```go\nfunc WithExtraScalars(names ...string) Option\n```\nWithExtraScalars adds type names that should be treated as scalars (kept typed) in addition to the built-in set (string, bool, float64, int64, int).\n\n```go\nfunc WithHeaderComment(comment string) Option\n```\nWithHeaderComment overrides the default \"DO NOT EDIT\" header comment.\n\n```go\nfunc WithPackageName(name string) Option\n```\nWithPackageName sets the Go package name for generated files. Default: basename of the output directory.\n\n```go\nfunc WithSortFields() Option\n```\nWithSortFields sorts generated fields: primary key fields (named \"ID\") first, then alphabetically by name. ExtraFields always come before source fields, preserving their original order.\n\n```go\ntype StructConfig struct {\n\t// SourceName is the struct name in the source file (e.g. \"VulnerabilityFinding\").\n\tSourceName string\n\t// OutputName is the generated struct name (e.g. \"customVulnerabilityFinding\").\n\tOutputName string\n\t// OutputFile is the filename for the generated file (e.g. \"vulnerability_finding_generated.go\").\n\tOutputFile string\n\t// ExtraFields are additional fields prepended to the generated struct.\n\tExtraFields []Field\n}\n```\nStructConfig defines how to transform one source struct into an optimized version.\n\n","path":"github.com/cloudquery/codegen/structs","name":"structs","synopsis":"Package structs provides code generation utilities for optimizing Go struct types.","isRedistributable":true}
