Documentation
¶
Overview ¶
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.
Index ¶
- func ConfigurationFile(cs ConfigurationSchema, packageName, from string) ([]byte, error)
- func DataSourceFile(ds DataSourceSchema, from string) ([]byte, error)
- func GoMod(modulePath, replaceUnobin string) ([]byte, error)
- func LibraryFile(packageName string, resources []ResourceSchema, dataSources []DataSourceSchema, ...) ([]byte, error)
- func PointerType(goType string) string
- func ResourceFile(rs ResourceSchema, from string) ([]byte, error)
- func UBTag(fieldName string) string
- type ConfigurationSchema
- type DataSourceSchema
- type Field
- type Input
- type Output
- type ResourceSchema
- type SchemaAdapter
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ConfigurationFile ¶
func ConfigurationFile(cs ConfigurationSchema, packageName, from string) ([]byte, error)
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 ¶
func DataSourceFile(ds DataSourceSchema, from string) ([]byte, error)
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. 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 ¶
func ResourceFile(rs ResourceSchema, from string) ([]byte, error)
ResourceFile renders a Go source file for one resource into the resources/ sub-package.
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 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
}
Input configures a generation run.
type Output ¶
Output reports what was generated.
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.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package tf parses Terraform provider schemas (from "terraform providers schema -json") and converts them to gogen.ResourceSchema values for Go code generation.
|
Package tf parses Terraform provider schemas (from "terraform providers schema -json") and converts them to gogen.ResourceSchema values for Go code generation. |