codegen

package
v0.26.0 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2026 License: MIT Imports: 12 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrCannotGenerateCodegenPackageContentError = fmt.Errorf("cannot generate codegen.Package content")

Functions

This section is empty.

Types

type AliasType

type AliasType struct {
	Decl

	Alias string
	Name  string
}

func (AliasType) Generate

func (p AliasType) Generate(out *Emitter) error

func (AliasType) GetName

func (p AliasType) GetName() string

GetName returns the alias, the name the declaration introduces. With it, every package-level declaration is Named, so Package.Generate orders them by one key instead of treating an alias as equal to everything.

type ArrayType

type ArrayType struct {
	Type Type
}

func (ArrayType) Generate

func (a ArrayType) Generate(out *Emitter) error

func (ArrayType) IsNillable

func (ArrayType) IsNillable() bool

type Constant

type Constant struct {
	Type  Type
	Name  string
	Value any
}

Constant is a "const <name> = <value>".

func (*Constant) Generate

func (c *Constant) Generate(out *Emitter) error

func (*Constant) GetName

func (c *Constant) GetName() string

type CustomNameType

type CustomNameType struct {
	Type     string
	Nillable bool
}

func (CustomNameType) Generate

func (p CustomNameType) Generate(out *Emitter) error

func (CustomNameType) IsNillable

func (p CustomNameType) IsNillable() bool

type Decl

type Decl interface {
	Generate(out *Emitter) error
}

type DurationType

type DurationType struct{}

DurationType exists to provide special handling when validating durations. Having a dedicated type for durations allows the validator to differentiate between durations and other types.

func (DurationType) Generate

func (t DurationType) Generate(out *Emitter) error

func (DurationType) GetName

func (t DurationType) GetName() string

func (DurationType) IsNillable

func (t DurationType) IsNillable() bool

type Emitter

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

func NewEmitter

func NewEmitter(maxLineLength int32) *Emitter

func (*Emitter) Bytes

func (e *Emitter) Bytes() []byte

func (*Emitter) Comment

func (e *Emitter) Comment(s string)

func (*Emitter) Commentf

func (e *Emitter) Commentf(s string, args ...any)

func (*Emitter) Indent

func (e *Emitter) Indent(n int32)

func (*Emitter) MaxLineLength

func (e *Emitter) MaxLineLength() int32

func (*Emitter) Newline

func (e *Emitter) Newline()

func (*Emitter) Printf

func (e *Emitter) Printf(format string, args ...any)

func (*Emitter) Printlnf

func (e *Emitter) Printlnf(format string, args ...any)

func (*Emitter) String

func (e *Emitter) String() string

type EmptyInterfaceType

type EmptyInterfaceType struct{}

func (EmptyInterfaceType) Generate

func (EmptyInterfaceType) Generate(out *Emitter) error

func (EmptyInterfaceType) IsNillable

func (EmptyInterfaceType) IsNillable() bool

type File

type File struct {
	FileName string
	Package  Package
}

func (*File) Generate

func (p *File) Generate(out *Emitter) error

type Fragment

type Fragment func(*Emitter)

Fragment is an arbitrary piece of code.

func (Fragment) Generate

func (f Fragment) Generate(out *Emitter) error

type Import

type Import struct {
	Name          string
	QualifiedName string
}

Import is a "type <name> = <definition>".

func (*Import) Generate

func (i *Import) Generate(out *Emitter) error

type MapType

type MapType struct {
	KeyType, ValueType Type
}

func (MapType) Generate

func (p MapType) Generate(out *Emitter) error

func (MapType) IsNillable

func (MapType) IsNillable() bool

type Method

type Method struct {
	Impl func(*Emitter) error
	Name string
}

Method defines a method and how to generate it.

func (*Method) Generate

func (m *Method) Generate(out *Emitter) error

func (*Method) GetName

func (m *Method) GetName() string

type Named

type Named interface {
	Decl
	GetName() string
}

type NamedType

type NamedType struct {
	Package *Package
	Decl    *TypeDecl
	// Alias overrides the import alias used to qualify the type reference
	// (e.g. emit `headerv1.Foo` instead of `v1.Foo`). When empty, the alias
	// is derived from Package.QualifiedName via Package.Name(). Set this in
	// pkg/generator when a SchemaMapping carries an explicit ImportAlias —
	// keep pkg/codegen ignorant of the schema-side decision by treating the
	// field as opaque IR data.
	Alias string
}

func (NamedType) Generate

func (t NamedType) Generate(out *Emitter) error

func (NamedType) GetName

func (t NamedType) GetName() string

func (NamedType) IsNillable

func (t NamedType) IsNillable() bool

type NullType

type NullType struct{}

func (NullType) Generate

func (NullType) Generate(out *Emitter) error

func (NullType) IsNillable

func (NullType) IsNillable() bool

type Package

type Package struct {
	QualifiedName string
	Comment       string
	Decls         []Decl
	Imports       []Import
}

Package is a "package <name>; <body>".

func (*Package) AddDecl

func (p *Package) AddDecl(d Decl)

func (*Package) AddImport

func (p *Package) AddImport(qualifiedName, alias string)

func (*Package) Generate

func (p *Package) Generate(out *Emitter) error

func (*Package) Name

func (p *Package) Name() string

type PointerType

type PointerType struct {
	Type Type
}

func (PointerType) Generate

func (p PointerType) Generate(out *Emitter) error

func (PointerType) IsNillable

func (PointerType) IsNillable() bool

type PrimitiveType

type PrimitiveType struct {
	Type string
}

func (PrimitiveType) Generate

func (p PrimitiveType) Generate(out *Emitter) error

func (PrimitiveType) IsNillable

func (PrimitiveType) IsNillable() bool

type RegexpVar

type RegexpVar struct {
	Name    string
	Pattern string
}

RegexpVar is a "var <name> = regexp.MustCompile(`<pattern>`)" declaration. Used so generated validators can reuse one compiled regex per pattern instead of paying compilation cost on every call to regexp.MatchString.

func (*RegexpVar) Generate

func (r *RegexpVar) Generate(out *Emitter) error

func (*RegexpVar) GetName

func (r *RegexpVar) GetName() string

type StructField

type StructField struct {
	Name         string
	Type         Type
	Comment      string
	Tags         string
	JSONName     string
	DefaultValue any
	SchemaType   *schemas.Type
}

func (*StructField) Generate

func (f *StructField) Generate(out *Emitter) error

func (*StructField) GetName

func (f *StructField) GetName() string

type StructType

type StructType struct {
	Fields             []StructField
	RequiredJSONFields []string
	DefaultValue       any
}

func (*StructType) AddField

func (s *StructType) AddField(f StructField)

func (*StructType) Generate

func (s *StructType) Generate(out *Emitter) error

func (*StructType) IsNillable

func (*StructType) IsNillable() bool

type Type

type Type interface {
	Decl
	IsNillable() bool
}

func PrimitiveTypeFromJSONSchemaType

func PrimitiveTypeFromJSONSchemaType(
	jsType,
	format string,
	pointer,
	minIntSize bool,
	minimum **float64,
	maximum **float64,
	exclusiveMinimum **any,
	exclusiveMaximum **any,
) (Type, error)

func WrapTypeInPointer

func WrapTypeInPointer(t Type) Type

type TypeDecl

type TypeDecl struct {
	Name       string
	Type       Type
	Comment    string
	SchemaType *schemas.Type
}

TypeDecl is a "type <name> = <definition>".

func (*TypeDecl) Generate

func (td *TypeDecl) Generate(out *Emitter) error

func (*TypeDecl) GetName

func (td *TypeDecl) GetName() string

type Var

type Var struct {
	Type  Type
	Name  string
	Value any
}

Var is a "var <name> = <value>".

func (*Var) Generate

func (v *Var) Generate(out *Emitter) error

func (*Var) GetName

func (v *Var) GetName() string

Jump to

Keyboard shortcuts

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