ctn

package
v0.0.0-...-2501437 Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2022 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func InitializeDIForUtil

func InitializeDIForUtil(di DI) (err error)

Initializes DI, so that DICommonUtil can be used with it. For now it only registers `Cleaner` and `CleanRegistry`.

func Must

func Must[T any](data T, err error) (res T)

Generic version of must function.

Types

type CleanRegistry

type CleanRegistry interface {
	Register(closeable io.Closer)
}

type Cleaner

type Cleaner interface {
	CleanRegistry

	// Closes all registered closers.
	Clean() (err error)
}

func NewCleaner

func NewCleaner() Cleaner

type DI

type DI = *dig.Container

Implementation of DI container used. For now dig is used, rather than some interface for sake of simplicity.

func NewDI

func NewDI() DI

Creates new empty DI container.

type DICommonUtil

type DICommonUtil struct {
	DI
}

Getters/accessors for common utils used in DI by compilation stuff. Note: di must be initialized first in order to use it.

func (*DICommonUtil) CleanupClosers

func (di *DICommonUtil) CleanupClosers() (err error)

Cleans up all closes, which were registered in CleanRegistry.

func (*DICommonUtil) RegisterCloser

func (di *DICommonUtil) RegisterCloser(c io.Closer) (err error)

type InputFS

type InputFS fsal.FS

Common DI type for input file system in DI container.

type OutputFS

type OutputFS fsal.FS

Common DI type for output file system in DI container.

type SimpleStage

type SimpleStage struct {
	InitializeImpl func(ctx StageContext) (err error)
	CompileImpl    func(ctx StageContext, c DI) (err error)
	RewriteImpl    func(ctx StageContext, current DI, newContainer DI) (err error)
	ShutdownImpl   func(ctx StageContext, c DI) (err error)
}

Stage, which implements it's functionality using functions provided by user. Functions, which are not provided are noop.

func (*SimpleStage) Compile

func (ss *SimpleStage) Compile(ctx StageContext, c DI) (err error)

func (*SimpleStage) Initialize

func (ss *SimpleStage) Initialize(ctx StageContext) (err error)

func (*SimpleStage) Rewrite

func (ss *SimpleStage) Rewrite(ctx StageContext, current DI, newContainer DI) (err error)

func (*SimpleStage) Shutdown

func (ss *SimpleStage) Shutdown(ctx StageContext, c DI) (err error)

type Stage

type Stage interface {
	// Initializes container.
	// Called before rewriting of previous container is performed.
	Initialize(ctx StageContext) (err error)

	// Performs actual compilation - registers DI types, which
	// are result of compilation.
	Compile(ctx StageContext) (err error)

	// Rewrites all entries from current DI container to next stage's DI container.
	// So that all redundant dependencies are dropped.
	//
	// Called after compile.
	Rewrite(ctx StageContext, newContainer DI) (err error)

	// Shutdowns DI container.
	// This function must perform any kind of cleanup.
	Shutdown(ctx StageContext) (err error)
}

Represents single compilation stage, which is implemented by user.

type StageContext

type StageContext interface {
	context.Context
	// Returns compilation-wide DI container.
	GetGlobalContainer() DI
	GetStageContanier() DI
}

type StagedCompiler

type StagedCompiler struct {
	InitializeGlobalContainer func(ctx context.Context, globalDI DI) (err error)
	Stages                    []Stage
}

func (*StagedCompiler) RunCompilation

func (sm *StagedCompiler) RunCompilation(ctx context.Context) (err error)

type StagedCompilerResult

type StagedCompilerResult struct {
	LastStageDI DI
	GlobalDI    DI
}

Jump to

Keyboard shortcuts

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