service

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: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// VarDatadir is the variable name that
	// idenfies a Service's data directory path.
	VarDatadir = "datadir"

	// VarOpenTag is the string opening a variable name
	// to be replaced with its real value.
	VarOpenTag = "{{"
	// VarParentSep separates parent service's name with
	// parent service's variable name, when addressing a parent's variable.
	VarParentSep = "."
	// TemplateOpenTag is the string closing a variable name
	// to be replaced with its real value.
	VarCloseTag = "}}"
)

Variables

View Source
var (
	// DefaultPkgManager is the default package manager command to install OS packages.
	DefaultPkgManager = []string{"pkcon", "install", "-y"}
)

Functions

This section is empty.

Types

type DepSet

type DepSet struct {
	*set.Set[string]
}

DepSet is an unordered set of Service names.

func NewDepSet

func NewDepSet(capacity int) DepSet

NewDepSet crates an empty DepSet with an initial capacity.

func NewDepSetFrom

func NewDepSetFrom(items []string) DepSet

NewDepSetFrom creates a DepSet from a list of Service names.

func (DepSet) Equal

func (ds DepSet) Equal(ds2 DepSet) bool

Equal returns true if ds is equal to ds2.

func (*DepSet) UnmarshalYAML

func (ds *DepSet) UnmarshalYAML(node *yaml.Node) error

UnmarshalYAML implements the yaml.Unmarshaler interface.

type FilePath

type FilePath struct {
	Path string `yaml:"path"`
	Mode uint16 `yaml:"mode"`
}

FilePath is a filesystem file path with its file mode.

func (*FilePath) UnmarshalYAML

func (lp *FilePath) UnmarshalYAML(node *yaml.Node) error

UnmarshalYAML implements the yaml.Unmarshaler interface.

type Service

type Service struct {
	// Name uniquely identifies a Service.
	Name string `yaml:"-"`

	// Depends is a set of Service names upon which this Service depends.
	Depends *DepSet `yaml:"depends"`

	// Setup is a script (UNIX Shell or Powershell, depending on the operating system)
	// to run before reinstalling and/or restoring any resources.
	Setup *string `yaml:"setup"`

	// PkgManager is combination of command name
	// and arguments to reinstall operating system packages.
	// It must accept a list of package names appended to it.
	PkgManager []string `yaml:"pkgmanager"`

	// Packages is a list of operating system packages to reinstall.
	// It will be appended as-is to PkgManager.
	Packages []string `yaml:"packages"`

	// Links is a collection of symlinks to restore. Their source path
	// is relative to Service's linkdir.
	Links map[string]FilePath `yaml:"links"`

	// Variables is a collection of local variables associated to this Service.
	// A template engine may use them to edit files in place before copying them,
	// or to customize Setup and Finalize scripts.
	// Variables will always contain at least VarDatadir of Datadir kind.
	Variables map[string]VarValue `yaml:"variables"`

	// Copies is a collection of files to copy. Their source path
	// is relative to Service's datadir. A template engine may use Variables
	// to customize the content.
	Copies map[string]FilePath `yaml:"copies"`

	// Setup is a script (UNIX Shell or Powershell, depending on the operating system)
	// to run after reinstalling and/or restoring any resources.
	Finalize *string `yaml:"finalize"`
}

Service is a collection of resources to reinstall/restore on an operating system. All fields except Name are optional.

func New

func New(name string) *Service

New creates a Service with a given name. Variables will contain VarDatadir and PkgManager will be DefaultPkgManager.

func NewFromYAML

func NewFromYAML(name string, yml []byte) (*Service, error)

NewFromYAML creates a Service with a given name whose fields are defined by a buffered YAML document.

func NewFromYAMLReader

func NewFromYAMLReader(name string, rd io.Reader) (*Service, error)

NewFromYAML creates a Service with a given name whose fields are defined by a streaming YAML document.

func (*Service) Hash

func (srv *Service) Hash() string

Hash returns a string that uniquely identifies this Service. It currently returns Name.

type VarKind

type VarKind string

VarKind is a kind of variable. Any non-ClearText kind will require a solver to extract the value.

const (
	// ClearText is the simplest VarKind. Any variable of type ClearText
	// has its value immediately accessible.
	ClearText VarKind = "cleartext"

	// Datadir is the path of a Service's data directory.
	Datadir VarKind = "datadir"
)

type VarValue

type VarValue struct {
	// Kind is the variable kind. Unless it's ClearText, a solver is required
	// to get the real value.
	Kind VarKind `yaml:"kind"`
	// Value is either the final value, if Kind is ClearText, or an intermediate value.
	Value string `yaml:"value"`
}

VarValue is a variable's value.

func (*VarValue) UnmarshalYAML

func (val *VarValue) UnmarshalYAML(node *yaml.Node) error

UnmarshalYAML implements the yaml.Unmarshaler interface.

Jump to

Keyboard shortcuts

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