ir

package
v0.0.0-...-9a5c20e Latest Latest
Warning

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

Go to latest
Published: May 2, 2024 License: BSD-3-Clause Imports: 9 Imported by: 39

README

ir

import "github.com/blueprint-uservices/blueprint/blueprint/pkg/ir"

Package ir provides the basic interfaces for Blueprint's Internal Representation (IR) and for subsequently generating application artifacts such as code and container images.

An application's IR representation is produced by constructing and then building a wiring spec using methods from the wiring package and from wiring extensions provided by plugins.

Index

func CleanName

func CleanName(name string) string

Returns name with only alphanumeric characters and all other symbols converted to underscores.

CleanName is primarily used by plugins to convert user-defined service names into names that are valid as e.g. environment variables, command line arguments, etc.

func Filter

func Filter[T any](nodes []IRNode) []T

Returns a slice containing only nodes of type T

func Is

func Is[T any](nodeType any) bool

Reports whether nodeType is an instance of type T

func PrettyPrintNamespace

func PrettyPrintNamespace(instanceName string, namespaceType string, argNodes []IRNode, childNodes []IRNode) string

func RegisterDefaultNamespace

func RegisterDefaultNamespace[T IRNode](name string, buildFunc func(outputDir string, nodes []IRNode) error)

When building an application, any IR nodes of type T that reside within the top-level application will be built using the specified buildFunc.

type ApplicationNode

The IR Node that represents the whole application. Building a wiring spec will return an ApplicationNode. An ApplicationNode can be built with the GenerateArtifacts method.

type ApplicationNode struct {
    IRNode
    ArtifactGenerator

    ApplicationName string
    Children        []IRNode
}

func (*ApplicationNode) GenerateArtifacts
func (app *ApplicationNode) GenerateArtifacts(dir string) error

func (*ApplicationNode) Name
func (node *ApplicationNode) Name() string

func (*ApplicationNode) String
func (node *ApplicationNode) String() string

Print the IR graph

type ArtifactGenerator

Most IRNodes can generate code artifacts but they do so in the context of some BuildContext. A few IRNodes, however, can generate artifacts independent of any external context. Those IRNodes implement the ArtifactGenerator interface. Typically these are namespace nodes such as golang processes, linux containers, or docker deployments.

type ArtifactGenerator interface {

    // Generate all artifacts for this node to the specified dir on the local filesystem.
    GenerateArtifacts(dir string) error
}

type BuildContext

All artifact generation occurs in the context of some BuildContext.

Plugins that control the artifact generation process should implement this interface.

type BuildContext interface {
    VisitTracker
    ImplementsBuildContext()
}

type IRConfig

IRConfig is an IR node that represents a configured or configurable variable. In a generated application, IRConfig nodes typically map down to things like environment variables or command line arguments, and can be passed all the way into specific application-level instances. IRConfig is also used for addressing.

type IRConfig interface {
    IRNode
    Optional() bool
    // At various points during the build process, an IRConfig node might have a concrete value
    // set, or it might be left unbound.
    HasValue() bool

    // Returns the current value of the config node if it has been set.  Config values
    // are always strings.
    Value() string
    ImplementsIRConfig()
}

type IRMetadata

Metadata is an IR node that exists in the IR of an application but does not build any artifacts or provide configuration or anything like that.

type IRMetadata interface {
    IRNode
    ImplementsIRMetadata()
}

type IRNode

All nodes implement the IRNode interface

type IRNode interface {
    Name() string
    String() string
}

func FilterNodes
func FilterNodes[T any](nodes []IRNode) []IRNode

Returns a slice containing only nodes of type T

func Remove
func Remove[T any](nodes []IRNode) []IRNode

Returns a slice containing all nodes except those of type T

type IRValue

A hard-coded value

type IRValue struct {
    Value string
}

func (*IRValue) Name
func (v *IRValue) Name() string

func (*IRValue) String
func (v *IRValue) String() string

type VisitTracker

A Blueprint application can potentially have multiple IR node instances spread across the application that generate the same code.

Visit tracker is a utility method used during artifact generation to prevent nodes from unnecessarily generating the same artifact repeatedly, when once will suffice.

type VisitTracker interface {
    // Returns false on the first invocation of name; true on subsequent invocations
    Visited(name string) bool
}

type VisitTrackerImpl

Basic implementation of the VisitTracker interface

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

func (*VisitTrackerImpl) Visited
func (tracker *VisitTrackerImpl) Visited(name string) bool

Generated by gomarkdoc

Documentation

Overview

Package ir provides the basic interfaces for Blueprint's Internal Representation (IR) and for subsequently generating application artifacts such as code and container images.

An application's IR representation is produced by constructing and then building a wiring spec using methods from the wiring package and from wiring extensions provided by plugins.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CleanName

func CleanName(name string) string

Returns name with only alphanumeric characters and all other symbols converted to underscores.

CleanName is primarily used by plugins to convert user-defined service names into names that are valid as e.g. environment variables, command line arguments, etc.

func Filter

func Filter[T any](nodes []IRNode) []T

Returns a slice containing only nodes of type T

func Is

func Is[T any](nodeType any) bool

Reports whether nodeType is an instance of type T

func PrettyPrintNamespace

func PrettyPrintNamespace(instanceName string, namespaceType string, argNodes []IRNode, childNodes []IRNode) string

func RegisterDefaultNamespace

func RegisterDefaultNamespace[T IRNode](name string, buildFunc func(outputDir string, nodes []IRNode) error)

When building an application, any IR nodes of type T that reside within the top-level application will be built using the specified buildFunc.

Types

type ApplicationNode

type ApplicationNode struct {
	IRNode
	ArtifactGenerator

	ApplicationName string
	Children        []IRNode
}

The IR Node that represents the whole application. Building a wiring spec will return an ApplicationNode. An ApplicationNode can be built with the GenerateArtifacts method.

func (*ApplicationNode) GenerateArtifacts

func (app *ApplicationNode) GenerateArtifacts(dir string) error

func (*ApplicationNode) Name

func (node *ApplicationNode) Name() string

func (*ApplicationNode) String

func (node *ApplicationNode) String() string

Print the IR graph

type ArtifactGenerator

type ArtifactGenerator interface {

	// Generate all artifacts for this node to the specified dir on the local filesystem.
	GenerateArtifacts(dir string) error
}

Most IRNodes can generate code artifacts but they do so in the context of some BuildContext. A few IRNodes, however, can generate artifacts independent of any external context. Those IRNodes implement the ArtifactGenerator interface. Typically these are namespace nodes such as golang processes, linux containers, or docker deployments.

type BuildContext

type BuildContext interface {
	VisitTracker
	ImplementsBuildContext()
}

All artifact generation occurs in the context of some BuildContext.

Plugins that control the artifact generation process should implement this interface.

type IRConfig

type IRConfig interface {
	IRNode
	Optional() bool
	// At various points during the build process, an IRConfig node might have a concrete value
	// set, or it might be left unbound.
	HasValue() bool

	// Returns the current value of the config node if it has been set.  Config values
	// are always strings.
	Value() string
	ImplementsIRConfig()
}

IRConfig is an IR node that represents a configured or configurable variable. In a generated application, IRConfig nodes typically map down to things like environment variables or command line arguments, and can be passed all the way into specific application-level instances. IRConfig is also used for addressing.

type IRMetadata

type IRMetadata interface {
	IRNode
	ImplementsIRMetadata()
}

Metadata is an IR node that exists in the IR of an application but does not build any artifacts or provide configuration or anything like that.

type IRNode

type IRNode interface {
	Name() string
	String() string
}

All nodes implement the IRNode interface

func FilterNodes

func FilterNodes[T any](nodes []IRNode) []IRNode

Returns a slice containing only nodes of type T

func Remove

func Remove[T any](nodes []IRNode) []IRNode

Returns a slice containing all nodes except those of type T

func Split

func Split[T any](nodes []IRNode) (remaining []IRNode, matches []T)

Returns a slice containing only nodes of type T, and a slice containing all other nodes

type IRValue

type IRValue struct {
	Value string
}

A hard-coded value

func (*IRValue) Name

func (v *IRValue) Name() string

func (*IRValue) String

func (v *IRValue) String() string

type VisitTracker

type VisitTracker interface {
	// Returns false on the first invocation of name; true on subsequent invocations
	Visited(name string) bool
}

A Blueprint application can potentially have multiple IR node instances spread across the application that generate the same code.

Visit tracker is a utility method used during artifact generation to prevent nodes from unnecessarily generating the same artifact repeatedly, when once will suffice.

type VisitTrackerImpl

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

Basic implementation of the VisitTracker interface

func (*VisitTrackerImpl) Visited

func (tracker *VisitTrackerImpl) Visited(name string) bool

Jump to

Keyboard shortcuts

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