codegen

package
v0.0.0-...-55b549c Latest Latest
Warning

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

Go to latest
Published: Oct 6, 2025 License: GPL-3.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Generator

type Generator struct {
	// contains filtered or unexported fields
}

Generator generates Go SDK code from Proxmox API schema.

The generator orchestrates the entire SDK generation process:

  • Reading and parsing schema files
  • Generating code using templates
  • Formatting and validating generated code
  • Writing files to the output directory

It uses the template engine internally to transform schema structures into production-ready Go code.

func NewGenerator

func NewGenerator() *Generator

NewGenerator creates a new code generator.

The generator is ready to use immediately with sensible defaults. It creates an internal template engine for code generation.

Example usage:

gen := NewGenerator()
err := gen.GenerateFromSchemaFile("schema.json", "output/")

func (*Generator) FormatCode

func (g *Generator) FormatCode(source string) (string, error)

FormatCode formats Go source code using gofmt.

This ensures all generated code follows standard Go formatting conventions. It uses go/format.Source internally, which validates syntax and applies standard formatting rules.

If the source code has syntax errors, this method returns an error.

func (*Generator) GenerateFromSchemaFile

func (g *Generator) GenerateFromSchemaFile(schemaFile, outputDir string) error

GenerateFromSchemaFile reads a schema JSON file and generates the SDK.

This is a convenience method that combines reading a schema file, parsing it, and generating the SDK in one call. It's the recommended way to generate the SDK from a file.

The schema file should be a JSON file containing a parsed Proxmox API schema (typically generated by the schema generator).

Example:

gen := NewGenerator()
err := gen.GenerateFromSchemaFile("schema/apiSchema.json", "output/")

func (*Generator) GenerateSDK

func (g *Generator) GenerateSDK(schema *parser.APISchema, outputDir string) error

GenerateSDK generates the complete SDK from a parsed schema.

This is the main entry point for SDK generation from an already-parsed schema. It performs the following steps:

  1. Validates input parameters
  2. Generates code files using the template engine
  3. Formats all generated code with gofmt
  4. Writes files to the output directory

The output directory will be created if it doesn't exist. Generated files follow the structure:

outputDir/pkg/proxmox/client.go
outputDir/pkg/proxmox/types.go
outputDir/pkg/cluster/...  (future)

Example:

schema := &parser.APISchema{...}
err := gen.GenerateSDK(schema, "output/")

func (*Generator) ValidateGeneratedCode

func (g *Generator) ValidateGeneratedCode(pkgPath string) error

ValidateGeneratedCode validates that the generated code is syntactically correct.

This method checks all .go files in the specified package directory to ensure they contain valid Go syntax. It uses go/format.Source for validation, which will catch syntax errors.

This is useful as a post-generation sanity check to ensure the template engine produced valid code.

Example:

err := gen.ValidateGeneratedCode("output/pkg/proxmox")

func (*Generator) WriteFile

func (g *Generator) WriteFile(path, content string) error

WriteFile writes content to a file, creating directories as needed.

This method ensures that all parent directories exist before writing the file. Directories are created with 0755 permissions, files with 0644 permissions.

Special handling for test files (*_test.go): - Test files are only created if they don't already exist - This allows users to manually maintain and customize test files - Implementation files (*.go) are always overwritten

The method is used internally during SDK generation to write all generated files to disk.

type GeneratorConfig

type GeneratorConfig struct {
}

GeneratorConfig holds configuration for code generation.

Future enhancements may include:

  • Package name overrides
  • Custom template paths
  • Code style preferences
  • Output formatting options

Jump to

Keyboard shortcuts

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