repo

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2023 License: MPL-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNoService is returned when no Service could be found.
	ErrNoService = errors.New("service not found")
	// ErrNoVariable is returned when no variable name could be found.
	ErrNoVariable = errors.New("variable not found")
)

Functions

This section is empty.

Types

type DepGraph

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

DepGraph is the dependency graph of a service, akin to a family tree. Levels contain dependencies of dependencies: level 0 contains dependencies of the main service, while level 1 contains dependencies of all services in level 1, an so on. Levels are 0-indexed.

func NewDepGraph

func NewDepGraph(initalDepthCap int) DepGraph

NewDepGraph returns an empty DepGraph with an initial capacity.

func (*DepGraph) Depth

func (dg *DepGraph) Depth() int

Depth returns graph's current depth.

func (*DepGraph) Equal

func (dg *DepGraph) Equal(dg2 DepGraph) bool

Equal compares the graph with another by inspecting all the levels.

func (*DepGraph) Insert

func (dg *DepGraph) Insert(level int, srv *service.Service)

Insert inserts srv at level in the dependency graph. Insert panics if level is greater than graph's current depth.

func (*DepGraph) Level

func (dg *DepGraph) Level(index int) *DepSet

Level returns the dependency set for the level. Level panics if the level is greater than graph's current depth.

type DepSet

type DepSet struct {
	*set.HashSet[*service.Service, string]
}

DepSet is a unique set of services.

func NewDepSet

func NewDepSet(initialCap int) DepSet

NewDepSet returns an empty set of services with an initial capacity.

func (DepSet) Equal

func (ds DepSet) Equal(ds2 DepSet) bool

Equal compares the set with another.

type FS

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

FS is a repository based on a filesystem.

func NewFS

func NewFS(baseFS fs.FS) FS

NewFS creates a new filesystem-based repository from an existing filesystem.

func NewFSVariant

func NewFSVariant(baseFS fs.FS, variant string) FS

NewFSVariant creates a new FS repository from an existing filesystem. The new FS repository will return services for the given system variant.

func (FS) AllServices

func (repo FS) AllServices() ([]*service.Service, error)

AllServices returns all services in the filesystem.

func (FS) DataDir

func (repo FS) DataDir(name string) (string, error)

DataDir returns the data directory path for a hypothetical service. There is no guarantee that the path exists.

func (FS) LinkDir

func (repo FS) LinkDir(name string) (string, error)

DataDir returns the link directory path for a hypothetical service. There is no guarantee that the path exists.

func (FS) ResolveDeps

func (repo FS) ResolveDeps(srv *service.Service) (DepGraph, error)

ResolveDeps resolves the dependency graph for srv. If srv has no dependencies, the dependency graph will be empty.

func (FS) Service

func (repo FS) Service(name string) (*service.Service, error)

Service returns the service with the name provided.

type OSFS

type OSFS struct {
	fs.StatFS
	// contains filtered or unexported fields
}

OSFS circumvents the inability to check whether fs.FS is a real operating system path. FSRepo will use OSFS to discriminate a real OS path from a network, or a testing, file system.

Ideally, Go should provide the inverse operation of os.DirFS().

func NewOSFS

func NewOSFS(path string) OSFS

NewOSFS returns a new OSFS based on path.

type Repo

type Repo interface {
	// DataDir returns the data directory path of a service.
	DataDir(srvName string) (string, error)
	// Link returns the symlink directory path of a service.
	LinkDir(srvName string) (string, error)
	// ResolveDeps creates the dependency tree of a service.
	ResolveDeps(srv *service.Service) (DepGraph, error)
}

Repo is capable of fetching services from a source.

type VarSolver

type VarSolver interface {
	// Value resolves the intermediate value
	// of varName or returns an error.
	Value(varName string) (varValue string, err error)
}

VarSolver resolves the intermediate value of variables.

type Variables

type Variables struct {
	// Common is an optional collection of variables that services
	// might have in common. It is initially nil.
	Common map[string]string
	// contains filtered or unexported fields
}

Variables resolves and caches services' variables.

func NewVariables

func NewVariables() Variables

func (Variables) AddParent

func (vars Variables) AddParent(srv, parent string) error

AddParent adds parent to the parents of srv. That hints the two services are tied together and it may be useful to Get parent's variables as well when Getting srv's variables. AddParent returns ErrNoService if srv or parent does not exist.

func (Variables) Get

func (vars Variables) Get(service, key string) (string, error)

Get returns the value of a Service's variable, previously cached via Insert. If srv does not exist, ErrNoService is returned. If key does not exist, ErrNoVariable is returned.

func (*Variables) GobDecode

func (vars *Variables) GobDecode(data []byte) error

GobDecode implements the gob.GobDecoder interface.

func (Variables) GobEncode

func (vars Variables) GobEncode() ([]byte, error)

GobEncode implements the gob.GobEncoder interface.

func (Variables) Insert

func (vars Variables) Insert(srv, key string, val service.VarValue) error

Insert saves value for a service named srv under key. If the value is not clear text, it is resolved immediately and then cached. If key is already present for srv, Insert is no-op.

func (Variables) InsertMany

func (vars Variables) InsertMany(srv string, values map[string]service.VarValue) error

InsertMany is a convenience method to Insert multiple values.

func (Variables) Length

func (vars Variables) Length() int

Length returns how many variables were cached.

func (Variables) Parents

func (vars Variables) Parents(srv string) ([]string, error)

Parents returns the parent list of srv. If srv does not exist, ErrNoService is returned.

func (Variables) RegisterSolver

func (vars Variables) RegisterSolver(kind service.VarKind, solv VarSolver)

RegisterSolver registers a VarSolver for a VarKind.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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