model

package
v0.0.0-...-fcd239a Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ResourceDeclaration  = DeclarationType("Resource")
	ObjectDeclaration    = DeclarationType("Object")
	EnumDeclaration      = DeclarationType("Enum")
	InterfaceDeclaration = DeclarationType("Interface")
)
View Source
const (
	OrderAlphabetical = "alphabetical"
	OrderRanked       = "ranked"
)

Variables

This section is empty.

Functions

func ComparePropertyReferences

func ComparePropertyReferences(
	left PropertyReference,
	right PropertyReference,
) int

Types

type Declaration

type Declaration interface {
	Name() string
	ID() string
	Kind() DeclarationType
	Usage() []PropertyReference
	Package() *Package
	Description() []string
}

Declaration is a common interface for declarations found in Go files.

type DeclarationType

type DeclarationType string

type Enum

type Enum struct {
	TypeReference
	// contains filtered or unexported fields
}

func TryNewEnum

func TryNewEnum(spec dst.Spec, comments []string) (*Enum, bool)

func (*Enum) AddValue

func (e *Enum) AddValue(value *EnumValue)

func (*Enum) Description

func (e *Enum) Description() []string

func (*Enum) Kind

func (*Enum) Kind() DeclarationType

func (*Enum) Name

func (e *Enum) Name() string

func (*Enum) Package

func (e *Enum) Package() *Package

func (*Enum) SetPackage

func (e *Enum) SetPackage(pkg *Package)

func (*Enum) SetUsage

func (e *Enum) SetUsage(usage []PropertyReference)

func (*Enum) Usage

func (e *Enum) Usage() []PropertyReference

func (*Enum) Values

func (e *Enum) Values() []*EnumValue

type EnumValue

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

func TryNewEnumValue

func TryNewEnumValue(spec dst.Spec) (*EnumValue, bool)

func (*EnumValue) Description

func (v *EnumValue) Description() []string

func (*EnumValue) Kind

func (v *EnumValue) Kind() string

func (*EnumValue) Name

func (v *EnumValue) Name() string

func (*EnumValue) Value

func (v *EnumValue) Value() string

type Function

type Function struct {
	Name              string        // Name of the function/method
	Receiver          TypeReference // Type of the receiver (pointer or value)
	IsPointerReceiver bool          // Whether the receiver is a pointer
	Parameters        []Parameter   // Function parameters
	Results           []Parameter   // Return values
	// contains filtered or unexported fields
}

Function represents a method declared on a struct type.

func TryNewFunction

func TryNewFunction(
	decl *dst.FuncDecl,
) (*Function, bool)

TryNewFunction attempts to create a Function from a dst.FuncDecl. Returns the function and true if successful, nil and false otherwise.

func (*Function) DeclaredOn

func (f *Function) DeclaredOn() *Object

DeclaredOn returns the object this function is declared on.

func (*Function) Description

func (f *Function) Description() []string

Description returns the description of the function.

type FunctionList

type FunctionList []*Function

FunctionList is a slice of Function pointers.

type ImportReference

type ImportReference struct {
	ImportPath string
	Alias      string
}

func TryNewImportReference

func TryNewImportReference(imp *dst.ImportSpec) (ImportReference, bool)

func (*ImportReference) Name

func (imp *ImportReference) Name() string

type ImportReferenceSet

type ImportReferenceSet map[string]ImportReference

ImportReferenceSet is a set of ImportReference objects, indexed by their alias.

func NewImportReferenceSet

func NewImportReferenceSet(refs ...ImportReference) ImportReferenceSet

NewImportReferenceSet creates a new ImportReferenceSet and adds the provided ImportReferences to it.

func (ImportReferenceSet) Add

func (set ImportReferenceSet) Add(ref ImportReference)

Add adds an ImportReference to the set, using its alias as the key. If the alias already exists, it will be overwritten.

func (ImportReferenceSet) LookupImportPath

func (set ImportReferenceSet) LookupImportPath(
	typ TypeReference,
) (string, bool)

LookupImportPath looks up the import path for a given TypeReference in the ImportReferenceSet. It returns the import path and true if found, false otherwise.

type Interface

type Interface struct {
	TypeReference
	// contains filtered or unexported fields
}

Interface represents an interface type declaration.

func TryNewInterface

func TryNewInterface(
	spec dst.Spec,
	comments []string,
	importReferences map[string]ImportReference,
) (*Interface, bool)

TryNewInterface attempts to create an Interface from a dst.Spec. Returns the interface and true if successful, nil and false otherwise.

func (*Interface) AddImplementation

func (i *Interface) AddImplementation(obj *Object)

AddImplementation adds an object as an implementation of this interface.

func (*Interface) Description

func (i *Interface) Description() []string

Description returns the description of the interface.

func (*Interface) Embeds

func (i *Interface) Embeds() []TypeReference

Embeds returns all the embedded interfaces, in the order they were declared.

func (*Interface) Implementations

func (i *Interface) Implementations() []*Object

Implementations returns all the objects that implement this interface.

func (*Interface) Kind

func (*Interface) Kind() DeclarationType

Kind returns the declaration type.

func (*Interface) Method

func (i *Interface) Method(name string) (*Function, bool)

Method returns the method with the given name and true, or nil and false if not found.

func (*Interface) Methods

func (i *Interface) Methods() FunctionList

Methods returns all the methods of the interface, in alphabetical order.

func (*Interface) Name

func (i *Interface) Name() string

Name returns the name of the interface.

func (*Interface) Package

func (i *Interface) Package() *Package

Package returns the package this interface belongs to.

func (*Interface) SetPackage

func (i *Interface) SetPackage(pkg *Package)

SetPackage sets the package this interface belongs to.

func (*Interface) SetUsage

func (i *Interface) SetUsage(usage []PropertyReference)

SetUsage sets the list of properties that reference this interface.

func (*Interface) Usage

func (i *Interface) Usage() []PropertyReference

Usage returns the list of properties that reference this interface.

type MarkerSwitch

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

MarkerSwitch captures the presence of a specific marker read from the source code.

func MakeMarkerSwitch

func MakeMarkerSwitch(path ...string) MarkerSwitch

MakeMarkerSwitch creates a new MArkerSwitch with the given marker path. path is the marker path to look for.

func (*MarkerSwitch) Merge

func (m *MarkerSwitch) Merge(other MarkerSwitch)

Merge combines the supplied MetadataSwitch with the current one, returning an error if the values differ.

func (*MarkerSwitch) Seen

func (m *MarkerSwitch) Seen() bool

Seen returns true if this marker has been seen, false otherwise.

func (*MarkerSwitch) Update

func (m *MarkerSwitch) Update(markers *Markers)

Update checks for the desired marker in passed set of markers, updating the value if found.

type MarkerValue

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

MarkerValue captures the value of a specific marker read from the source code.

func MakeMarkerValue

func MakeMarkerValue(path ...string) MarkerValue

MakeMarkerValue creates a new MetadataValue that looks for the given marker path. path is the path to the desired value.

func (*MarkerValue) Merge

func (m *MarkerValue) Merge(other MarkerValue) error

Merge combines the supplied MetadataValue with the current one, returning an error if the values differ.

func (*MarkerValue) SetValue

func (m *MarkerValue) SetValue(value string) error

func (*MarkerValue) Update

func (m *MarkerValue) Update(markers *Markers) error

Update reads the value from the passed set of markers, updating the value if found. If a new value is found that's different from the current value, we return an error.

func (*MarkerValue) Value

func (m *MarkerValue) Value() (string, bool)

Value returns the current value of the metadata, if known.

type Markers

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

func NewMarkers

func NewMarkers(markers ...string) *Markers

func ParseComments

func ParseComments(comments []string) ([]string, *Markers)

ParseComments iterates over the comments and returns the description and any commands that are not part of the description TODO: Add optional varidic "cleanup" functions to allow for more complex comment parsing/cleanup.

func (*Markers) Add

func (m *Markers) Add(marker string)

Add a marker to the list.

func (*Markers) Any

func (m *Markers) Any() bool

func (*Markers) Exists

func (m *Markers) Exists(path ...string) bool

Exists returns true if the marker exists.

func (*Markers) Lookup

func (m *Markers) Lookup(path ...string) (Markers, bool)

Lookup a marker value by path, returning the final marker.

func (*Markers) Value

func (m *Markers) Value() string

type Object

type Object struct {
	TypeReference
	// contains filtered or unexported fields
}

func NewObjectType

func NewObjectType(
	name string,
	id string,
	description []string,
) *Object

func TryNewObject

func TryNewObject(
	spec dst.Spec,
	comments []string,
	importReferences map[string]ImportReference,
) (*Object, bool)

func (*Object) AddFunction

func (o *Object) AddFunction(fn *Function)

AddFunction adds a function to the object.

func (*Object) AddInterface

func (o *Object) AddInterface(iface *Interface)

AddInterface adds an interface that this object implements.

func (*Object) Description

func (o *Object) Description() []string

func (*Object) Embed

func (o *Object) Embed(name string) (*Property, bool)

Embed returns the embed with the given name and true, or nil and false if not found.

func (*Object) Embeds

func (o *Object) Embeds() PropertyList

Embeds returns all of the embeds of the object, in alphabetical order.

func (*Object) Function

func (o *Object) Function(name string) (*Function, bool)

Function returns the function with the given name and true, or nil and false if not found.

func (*Object) Functions

func (o *Object) Functions() FunctionList

Functions returns all the functions/methods of the object, in alphabetical order.

func (*Object) ImplementsInterfaces

func (o *Object) ImplementsInterfaces() []*Interface

ImplementsInterfaces returns all the interfaces this object implements, in alphabetical order.

func (*Object) Kind

func (*Object) Kind() DeclarationType

func (*Object) Package

func (o *Object) Package() *Package

func (*Object) Properties

func (o *Object) Properties() PropertyList

Properties returns all the properties of the object, in alphabetical order.

func (*Object) Property

func (o *Object) Property(name string) (*Property, bool)

Property returns the property with the given name and true, or nil and false if not found.

func (*Object) SetPackage

func (o *Object) SetPackage(p *Package)

func (*Object) SetUsage

func (o *Object) SetUsage(uses []PropertyReference)

func (*Object) Usage

func (o *Object) Usage() []PropertyReference

type Order

type Order string

type Package

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

Package is a struct containing all of the declarations found in a package directory.

func (*Package) Declaration

func (p *Package) Declaration(name string) (Declaration, bool)

Declaration returns the declaration with the given name, if found.

func (*Package) Declarations

func (p *Package) Declarations(order Order) []Declaration

func (*Package) Group

func (p *Package) Group() string

Group returns the group of the package, if known.

func (*Package) Interface

func (p *Package) Interface(name string) (*Interface, bool)

Interface returns the interface with the given name, if there is one.

func (*Package) Module

func (p *Package) Module() string

Module returns the module of the package.

func (*Package) Name

func (p *Package) Name() string

func (*Package) Object

func (p *Package) Object(name string) (*Object, bool)

Object returns the object with the given name, if there is one.

func (*Package) PropertiesRequiredByDefault

func (p *Package) PropertiesRequiredByDefault() string

func (*Package) Rank

func (p *Package) Rank(name string) int

Rank returns the usage rank (depth from the root resource) of the given declaration.

func (*Package) Version

func (p *Package) Version() string

Version returns the version of the package, if known.

type PackageBuilder

type PackageBuilder struct {
	Resources  []*Resource
	Objects    map[string]*Object
	Enums      []*Enum
	Interfaces map[string]*Interface
	Metadata   *PackageMarkers
	Config     *config.Config
	Log        logr.Logger
}

PackageBuilder is a builder for Package instances.

func (*PackageBuilder) AddEnums

func (b *PackageBuilder) AddEnums(enums ...*Enum)

AddEnums adds enums to the builder.

func (*PackageBuilder) AddInterfaces

func (b *PackageBuilder) AddInterfaces(interfaces ...*Interface)

AddInterfaces adds interfaces to the builder.

func (*PackageBuilder) AddObjects

func (b *PackageBuilder) AddObjects(objects ...*Object)

AddObjects adds objects to the builder.

func (*PackageBuilder) AddResources

func (b *PackageBuilder) AddResources(resources ...*Resource)

AddResources adds resources to the builder.

func (*PackageBuilder) Build

func (b *PackageBuilder) Build() *Package

Build creates a new Package from the builder.

type PackageMarkers

type PackageMarkers struct {
	Name   string // Name of this package.
	Module string // Reference to use when importing this package.

	DefaultGroup   string // Default group, based on directory name
	DefaultVersion string // Default version, based on directory name
	// contains filtered or unexported fields
}

PackageMarkers captures specific package markers read from the source code.

func NewPackageMarkers

func NewPackageMarkers() *PackageMarkers

func (*PackageMarkers) Group

func (m *PackageMarkers) Group() string

Group returns the group of the package, using the configured controller-runtime marker if set, or the directory name if not.

func (*PackageMarkers) Merge

func (m *PackageMarkers) Merge(other *PackageMarkers) error

func (*PackageMarkers) PropertiesRequiredByDefault

func (m *PackageMarkers) PropertiesRequiredByDefault() string

func (*PackageMarkers) Update

func (m *PackageMarkers) Update(markers *Markers) error

func (*PackageMarkers) Version

func (m *PackageMarkers) Version() string

Version returns the version of the package, using the configured controller-runtime marker if set, or the directory name if not.

type Parameter

type Parameter struct {
	Name string        // Name of the parameter (may be empty)
	Type TypeReference // Type of the parameter
}

Parameter represents a function parameter or return value.

func NewAnonymousParameter

func NewAnonymousParameter(
	typeRef TypeReference,
) Parameter

NewAnonymousParameter creates a new anonymous Parameter. typeRef is the type of the parameter.

func NewNamedParameter

func NewNamedParameter(
	name string,
	typeRef TypeReference,
) Parameter

NewNamedParameter creates a new named Parameter. name is the parameter name. typeRef is the type of the parameter.

type Property

type Property struct {
	Field      string // Name of the field
	Name       string // Serialized name of the field
	Type       TypeReference
	DeclaredOn PropertyContainer
	// contains filtered or unexported fields
}

func NewProperty

func NewProperty(
	name string,
	ref TypeReference,
	description []string,
) *Property

func TryNewProperty

func TryNewProperty(
	name string,
	field *dst.Field,
) (*Property, bool)

func (*Property) Description

func (p *Property) Description() []string

func (*Property) Required

func (p *Property) Required() string

type PropertyContainer

type PropertyContainer interface {
	Embeds() PropertyList
	Properties() PropertyList
	Package() *Package
}

type PropertyList

type PropertyList []*Property

type PropertyMarkers

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

func NewPropertyMarkers

func NewPropertyMarkers() *PropertyMarkers

func (*PropertyMarkers) Merge

func (m *PropertyMarkers) Merge(other *PropertyMarkers) error

func (*PropertyMarkers) Optional

func (m *PropertyMarkers) Optional() bool

func (*PropertyMarkers) Parse

func (m *PropertyMarkers) Parse(
	markers *Markers,
) error

func (*PropertyMarkers) ParseDecorations

func (m *PropertyMarkers) ParseDecorations(decs dst.NodeDecs) error

func (*PropertyMarkers) Required

func (m *PropertyMarkers) Required() bool

type PropertyReference

type PropertyReference struct {
	HostName string // Name of the container of this property
	HostID   string // Id of the container of this property
	Property string // Name of the property being referenced
}

func NewPropertyReference

func NewPropertyReference(
	host string,
	id string,
	property string,
) PropertyReference

type Resource

type Resource struct {
	Object
	Spec   *Property
	Status *Property
}

func TryNewResource

func TryNewResource(object *Object) (*Resource, bool)

func (*Resource) Kind

func (*Resource) Kind() DeclarationType

type TypeAssertionInfo

type TypeAssertionInfo struct {
	InterfaceName string // Name of the interface being implemented
	TypeName      string // Name of the type that implements the interface
	IsPointer     bool   // Whether the implementation is pointer-based (e.g., &Type{})
}

TypeAssertionInfo represents a type assertion of the form `var _ Interface = &Type{}`. These assertions are used to link interfaces to their implementations.

func NewTypeAssertionInfo

func NewTypeAssertionInfo(interfaceName, typeName string, isPointer bool) TypeAssertionInfo

NewTypeAssertionInfo creates a new TypeAssertionInfo.

type TypeReference

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

func NewTypeReferenceFromExpr

func NewTypeReferenceFromExpr(expr dst.Expr) TypeReference

func (*TypeReference) Display

func (ref *TypeReference) Display() string

func (*TypeReference) ID

func (ref *TypeReference) ID() string

func (*TypeReference) ImportPath

func (ref *TypeReference) ImportPath() string

func (*TypeReference) Name

func (ref *TypeReference) Name() string

func (*TypeReference) Package

func (ref *TypeReference) Package() string

Jump to

Keyboard shortcuts

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