generator

package
v0.3.6 Latest Latest
Warning

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

Go to latest
Published: Jun 29, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CollectNamespaces added in v0.2.1

func CollectNamespaces(namespaceMap map[string]*NamespaceTypes) []string

CollectNamespaces returns a sorted list of all namespaces present in the IDL. The empty namespace (for types without a namespace) is excluded from the list unless it's the only namespace present.

func CollectSortedNamespaces added in v0.2.1

func CollectSortedNamespaces(namespaceMap map[string]*NamespaceTypes) []string

func GetBaseName

func GetBaseName(typeName string) string

GetBaseName extracts the base name from a qualified type name Examples: "auth.User" -> "User", "inc.Response" -> "Response"

func GetCSharpType

func GetCSharpType(typeDef map[string]interface{}, allStructs map[string]*parser.Struct, allEnums map[string]*parser.Enum) string

writeParameterDeserializationCs writes C# code to determine the Type for parameter deserialization GetCSharpType converts a type definition to a C# Type object for deserialization

func GetNamespaceFromType

func GetNamespaceFromType(typeName string, namespaceField string) string

GetNamespaceFromType extracts the namespace from a type name It first checks the type's Namespace field, then falls back to extracting from the qualified name Examples: "auth.User" -> "auth", "User" (with namespace="auth") -> "auth"

func GroupTypesByNamespace

func GroupTypesByNamespace(idl *parser.IDL) map[string]*NamespaceTypes

GroupTypesByNamespace groups all types in the IDL by their namespace

func List

func List() []string

List returns a slice of all registered plugin names.

func NamespaceToPascalCase added in v0.2.1

func NamespaceToPascalCase(namespace string) string

func PrintFileCreated added in v0.1.9

func PrintFileCreated(fullPath string, fs *flag.FlagSet)

PrintFileCreated prints the relative path to a file if silent mode is not enabled

func Register

func Register(plugin Plugin)

Register registers a plugin with the registry. If a plugin with the same name is already registered, Register panics.

Types

type CSharpClientServer

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

CSharpClientServer is a plugin that generates C# HTTP server and client code from IDL

func NewCSharpClientServer

func NewCSharpClientServer() *CSharpClientServer

NewCSharpClientServer creates a new CSharpClientServer plugin instance

func (*CSharpClientServer) Generate

func (p *CSharpClientServer) Generate(idl *parser.IDL, fs *flag.FlagSet) error

Generate generates C# HTTP server and client code from the parsed IDL

func (*CSharpClientServer) Name

func (p *CSharpClientServer) Name() string

Name returns the plugin identifier

func (*CSharpClientServer) RegisterFlags

func (p *CSharpClientServer) RegisterFlags(fs *flag.FlagSet)

RegisterFlags registers CLI flags for this plugin

type CSharpNamespacePaths added in v0.2.1

type CSharpNamespacePaths struct {
	BaseDir     string
	PackageBase string
}

func NewCSharpNamespacePaths added in v0.2.1

func NewCSharpNamespacePaths(baseDir, packageBase string) CSharpNamespacePaths

func (CSharpNamespacePaths) EnsureAllNamespaceDirs added in v0.2.1

func (p CSharpNamespacePaths) EnsureAllNamespaceDirs(namespaceMap map[string]*NamespaceTypes) (map[string]string, error)

func (CSharpNamespacePaths) EnsureNamespaceDir added in v0.2.1

func (p CSharpNamespacePaths) EnsureNamespaceDir(namespace string) (string, error)

func (CSharpNamespacePaths) EnsureRuntimeDir added in v0.2.1

func (p CSharpNamespacePaths) EnsureRuntimeDir() (string, error)

func (CSharpNamespacePaths) GetNamespaceImportPrefix added in v0.2.1

func (p CSharpNamespacePaths) GetNamespaceImportPrefix() string

func (CSharpNamespacePaths) GetRuntimeImport added in v0.2.1

func (p CSharpNamespacePaths) GetRuntimeImport() string

func (CSharpNamespacePaths) ResolveNamespaceDir added in v0.2.1

func (p CSharpNamespacePaths) ResolveNamespaceDir(namespace string) string

func (CSharpNamespacePaths) ResolveOutputPath added in v0.2.1

func (p CSharpNamespacePaths) ResolveOutputPath(namespace, filename string) string

func (CSharpNamespacePaths) ResolveRuntimeDir added in v0.2.1

func (p CSharpNamespacePaths) ResolveRuntimeDir() string

type GoClientServer

type GoClientServer struct {
}

GoClientServer is a plugin that generates Go HTTP server and client code from IDL

func NewGoClientServer

func NewGoClientServer() *GoClientServer

NewGoClientServer creates a new GoClientServer plugin instance

func (*GoClientServer) Generate

func (p *GoClientServer) Generate(idl *parser.IDL, fs *flag.FlagSet) error

Generate generates Go HTTP server and client code from the parsed IDL

func (*GoClientServer) Name

func (p *GoClientServer) Name() string

Name returns the plugin identifier

func (*GoClientServer) RegisterFlags

func (p *GoClientServer) RegisterFlags(fs *flag.FlagSet)

RegisterFlags registers CLI flags for this plugin

type JavaClientServer

type JavaClientServer struct {
}

JavaClientServer is a plugin that generates Java HTTP server and client code from IDL

func NewJavaClientServer

func NewJavaClientServer() *JavaClientServer

NewJavaClientServer creates a new JavaClientServer plugin instance

func (*JavaClientServer) Generate

func (p *JavaClientServer) Generate(idl *parser.IDL, fs *flag.FlagSet) error

Generate generates Java HTTP server and client code from the parsed IDL

func (*JavaClientServer) Name

func (p *JavaClientServer) Name() string

Name returns the plugin identifier

func (*JavaClientServer) RegisterFlags

func (p *JavaClientServer) RegisterFlags(fs *flag.FlagSet)

RegisterFlags registers CLI flags for this plugin

type NamespaceTypes

type NamespaceTypes struct {
	Structs    []*parser.Struct
	Enums      []*parser.Enum
	Interfaces []*parser.Interface
	Errors     []*parser.ErrorDef
}

NamespaceTypes groups all types (structs, enums, interfaces, errors) for a single namespace

type Plugin

type Plugin interface {
	// Name returns the unique identifier for this plugin (e.g., "python-client-server")
	Name() string

	// RegisterFlags is called to allow the plugin to register its own CLI flags.
	// This is called before flag.Parse() so the plugin can add its flags to the
	// global FlagSet or create its own FlagSet.
	RegisterFlags(fs *flag.FlagSet)

	// Generate is called with the parsed IDL and the FlagSet to generate code output.
	// The plugin can access any flags it registered via RegisterFlags by querying
	// the provided FlagSet.
	Generate(idl *parser.IDL, fs *flag.FlagSet) error
}

Plugin defines the interface that all code generation plugins must implement

func Get

func Get(name string) (Plugin, bool)

Get retrieves a plugin by name from the registry. Returns the plugin and true if found, nil and false otherwise.

type PythonClientServer

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

PythonClientServer is a plugin that generates Python HTTP server and client code from IDL

func NewPythonClientServer

func NewPythonClientServer() *PythonClientServer

NewPythonClientServer creates a new PythonClientServer plugin instance

func (*PythonClientServer) Generate

func (p *PythonClientServer) Generate(idl *parser.IDL, fs *flag.FlagSet) error

Generate generates Python HTTP server and client code from the parsed IDL

func (*PythonClientServer) Name

func (p *PythonClientServer) Name() string

Name returns the plugin identifier

func (*PythonClientServer) RegisterFlags

func (p *PythonClientServer) RegisterFlags(fs *flag.FlagSet)

RegisterFlags registers CLI flags for this plugin

type PythonNamespacePaths added in v0.2.1

type PythonNamespacePaths struct {
	// BaseDir is the root output directory (from -dir flag)
	BaseDir string
	// PackageBase is the Python package prefix (from -package flag), e.g., "myapp.lib.rpc"
	PackageBase string
}

PythonNamespacePaths holds the resolved output paths for Python multi-namespace generation

func NewPythonNamespacePaths added in v0.2.1

func NewPythonNamespacePaths(baseDir, packageBase string) PythonNamespacePaths

NewPythonNamespacePaths creates a new PythonNamespacePaths instance

func (PythonNamespacePaths) EnsureAllNamespaceDirs added in v0.2.1

func (p PythonNamespacePaths) EnsureAllNamespaceDirs(namespaceMap map[string]*NamespaceTypes) (map[string]string, error)

EnsureAllNamespaceDirs creates directories for all namespaces in the IDL. This handles both include-driven (multiple namespaces) and single-file generation. Returns a map of namespace -> directory path.

func (PythonNamespacePaths) EnsureNamespaceDir added in v0.2.1

func (p PythonNamespacePaths) EnsureNamespaceDir(namespace string) (string, error)

EnsureNamespaceDir creates the directory for a namespace if it doesn't exist. Returns the resolved directory path.

func (PythonNamespacePaths) EnsureRuntimeDir added in v0.2.1

func (p PythonNamespacePaths) EnsureRuntimeDir() (string, error)

EnsureRuntimeDir creates the runtime directory if it doesn't exist. Returns the resolved directory path.

func (PythonNamespacePaths) GenerateAllInitPyFiles added in v0.2.1

func (p PythonNamespacePaths) GenerateAllInitPyFiles(namespaceMap map[string]*NamespaceTypes) error

GenerateAllInitPyFiles writes __init__.py files for all namespaces in the IDL. This is idempotent - safe to call multiple times.

func (PythonNamespacePaths) GenerateInitPy added in v0.2.1

func (p PythonNamespacePaths) GenerateInitPy(namespace string) error

GenerateInitPy writes an __init__.py file in the given directory. The file is idempotent - safe to regenerate without corruption. When packageBase is set, includes a relative import of the pulserpc runtime.

func (PythonNamespacePaths) ResolveNamespaceDir added in v0.2.1

func (p PythonNamespacePaths) ResolveNamespaceDir(namespace string) string

ResolveNamespaceDir returns the output directory path for a given namespace. When PackageBase is set, namespaces are placed under {BaseDir}/{PackageBase}/{namespace}/ For the empty/default namespace with PackageBase, returns {BaseDir}/{PackageBase}/ For named namespaces without PackageBase, returns {BaseDir}/{namespace}/

func (PythonNamespacePaths) ResolveOutputPath added in v0.2.1

func (p PythonNamespacePaths) ResolveOutputPath(namespace, filename string) string

ResolveOutputPath returns the full path for a file within a namespace directory. For example: ResolveOutputPath("common", "types.py") -> {BaseDir}/common/types.py

func (PythonNamespacePaths) ResolveRuntimeDir added in v0.2.1

func (p PythonNamespacePaths) ResolveRuntimeDir() string

ResolveRuntimeDir returns the output directory path for the pulserpc runtime. When PackageBase is set, returns {BaseDir}/{PackageBase}/pulserpc/ When PackageBase is empty, returns {BaseDir}/pulserpc/

type TSClientServer

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

TSClientServer is a plugin that generates TypeScript HTTP server and client code from IDL.

Three module styles are supported (see the -ts-module flag and the resolveModuleStyle helper):

  • "esm-node" (default) — Node-flavored ESM with explicit ".js" import suffixes and a runtime tree at pkg/runtime/runtimes/ts-node/.
  • "esm-bundler" — ESM without ".js" import suffixes, suitable for Vite/webpack/Next; uses the same runtime tree as esm-node, with the generator applying a post-process transform to strip the suffix.
  • "cjs" — CommonJS, using pkg/runtime/runtimes/ts-cjs/ and a transform that converts ESM imports/exports to require/module.exports.

func NewTSClientServer

func NewTSClientServer() *TSClientServer

NewTSClientServer creates a new TSClientServer plugin instance

func (*TSClientServer) Generate

func (p *TSClientServer) Generate(idl *parser.IDL, fs *flag.FlagSet) error

Generate generates TypeScript HTTP server and client code from the parsed IDL

func (*TSClientServer) Name

func (p *TSClientServer) Name() string

Name returns the plugin identifier

func (*TSClientServer) RegisterFlags

func (p *TSClientServer) RegisterFlags(fs *flag.FlagSet)

RegisterFlags registers CLI flags for this plugin

type TSNamespacePaths added in v0.2.1

type TSNamespacePaths struct {
	BaseDir     string
	PackageBase string
}

TSNamespacePaths holds the resolved output paths for TypeScript multi-namespace generation

func NewTSNamespacePaths added in v0.2.1

func NewTSNamespacePaths(baseDir, packageBase string) TSNamespacePaths

NewTSNamespacePaths creates a new TSNamespacePaths instance

func (TSNamespacePaths) EnsureNamespaceDir added in v0.2.1

func (p TSNamespacePaths) EnsureNamespaceDir(namespace string) error

EnsureNamespaceDir creates the output directory for a namespace if it doesn't exist.

func (TSNamespacePaths) EnsureRuntimeDir added in v0.2.1

func (p TSNamespacePaths) EnsureRuntimeDir() error

EnsureRuntimeDir creates the runtime directory if it doesn't exist.

func (TSNamespacePaths) ResolveNamespaceDir added in v0.2.1

func (p TSNamespacePaths) ResolveNamespaceDir(namespace string) string

ResolveNamespaceDir returns the output directory path for a given namespace. When PackageBase is set, namespaces are placed under {BaseDir}/{PackageBase}/{namespace}/ For the empty/default namespace with PackageBase, returns {BaseDir}/{PackageBase}/ For named namespaces without PackageBase, returns {BaseDir}/{namespace}/

func (TSNamespacePaths) ResolveRuntimeDir added in v0.2.1

func (p TSNamespacePaths) ResolveRuntimeDir() string

ResolveRuntimeDir returns the output directory path for the pulserpc runtime. When PackageBase is set, returns {BaseDir}/{PackageBase}/pulserpc/ When PackageBase is empty, returns {BaseDir}/pulserpc/

Jump to

Keyboard shortcuts

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