package gogen¶
Package gogen generates Go library source code from external schema formats (CFN registry schemas, TF provider schemas, DCL YAML). Sub-packages handle their own schema format; this package provides the shared types, type mapping, Go source rendering, and the top-level Generate orchestrator.
Functions¶
func ConfigurationFile¶
ConfigurationFile renders a configuration.go that declares the library-level provider config struct. Each field is wrapped in the cfg.* type matching its primitive Go type; non-required fields use a pointer so the decoder treats them as optional.
func DataSourceFile¶
DataSourceFile renders a Go source file for one data source into the data/ sub-package.
func GoMod¶
GoMod renders a go.mod file for a generated library. unobinVersion pins the unobin requirement when it is a release version; otherwise the v0.0.0 placeholder stands in, which only resolves with a replace. When replaceUnobin is non-empty, its absolute path is used to add a replace directive for the unobin dependency.
func LibraryFile¶
func LibraryFile(
packageName string,
resources []ResourceSchema,
dataSources []DataSourceSchema,
configuration *ConfigurationSchema,
modulePath, from string,
) ([]byte, error)
LibraryFile renders a library.go that registers all resources and data sources. It lives in the root package and imports the resources/ and data/ sub-packages (only the ones that have content). configuration may be nil; when present and non-empty, the registration references the ProviderConfig struct declared in configuration.go.
func PointerType¶
PointerType returns the pointer-wrapped Go type for optional fields. For bare types (string, int64, bool, float64) it returns "*T". For reference types ([]T, map[K]V, any) it returns the type unchanged since slices, maps, and interfaces are nil-able by default.
func ResourceFile¶
ResourceFile renders a Go source file for one resource into the resources/ sub-package.
func UBTag¶
UBTag returns the ub tag value for a field name.
Types¶
type ConfigurationSchema¶
ConfigurationSchema describes the operator-facing library configuration. Fields carry primitive Go types ("string", "int64", "float64", "bool", "[]string", "map[string]string", "any", ...); the renderer wraps each in the matching cfg.* wrapper type when it emits the struct.
type DataSourceSchema¶
type DataSourceSchema struct {
GoName string
CloudType string
Description string
InputFields []Field
OutputFields []Field
}
DataSourceSchema describes one cloud data source for code generation.
type Field¶
Field is one property of a resource or data source.
type Input¶
type Input struct {
Resources []string
OutDir string
ModulePath string
From string
ReplaceUnobin string // local path to github.com/cloudboss/unobin for go.mod replace
UnobinVersion string // the CLI's own unobin version, pinned in the generated go.mod
}
Input configures a generation run.
type Output¶
Output reports what was generated.
func Generate¶
Generate fetches schemas from the adapter, renders Go source files, and writes them to disk. Resources go into a resources/ sub-package and data sources into a data/ sub-package so that name collisions between resource and data source types cannot happen.
type ResourceSchema¶
type ResourceSchema struct {
GoName string
CloudType string
Description string
InputFields []Field
OutputFields []Field
CreateOnlyFields []string
PrimaryIdentifier []string
}
ResourceSchema describes one cloud resource type for code generation.
type SchemaAdapter¶
type SchemaAdapter interface {
Name() string
FetchResources(ctx context.Context, resources []string) ([]ResourceSchema, error)
FetchDataSources(ctx context.Context, resources []string) ([]DataSourceSchema, error)
FetchConfiguration(ctx context.Context) (*ConfigurationSchema, error)
}
SchemaAdapter fetches resource and data source schemas from an external source (e.g. a TF provider schema). FetchConfiguration returns the library-level configuration schema (the provider's own config block in TF). A nil return means the source has no configuration to expose; the generated library then omits the Configuration field.