model

package
v0.0.0-...-ce2211d Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2025 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ResourceDeclaration = DeclarationType("Resource")
	ObjectDeclaration   = DeclarationType("Object")
	EnumDeclaration     = DeclarationType("Enum")
)
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
	SetUsage([]PropertyReference)
	Package() *Package
	SetPackage(*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 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

func (ImportReferenceSet) Add

func (set ImportReferenceSet) Add(ref ImportReference)

func (ImportReferenceSet) LookupImportPath

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

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) 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() []*Property

Embeds returns all of the embeds of the object, 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() []*Property

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 NewPackage

func NewPackage(
	decl []Declaration,
	metadata *PackageMarkers,
	cfg *config.Config,
	log logr.Logger,
) *Package

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) 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 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 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 {
	Properties() []*Property
	Package() *Package
}

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 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