config

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2024 License: Apache-2.0, MIT Imports: 9 Imported by: 0

Documentation

Overview

Package config provides a mechanism for loading and consuming configuration file formats for Fhenix projects. This package provides the computed properties of the configuration format.

This means that defaults that are otherwise defined in the schema format are implicitly expanded in this computed format.

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidVersion = errors.New("invalid version")

Functions

This section is empty.

Types

type Config

type Config struct {
	// Mode is the mode type of template system being used for the output.
	Mode Mode

	// OutputDir is the output directory where generated output will be written.
	OutputDir string

	// Input are the packages that will be used as input for the generation.
	Input []*Package

	// Transforms contains a list of transforms to be applied to the input
	// definitions.
	Transforms []*Transform
}

Config represents the configuration that is used for generation within Fhenix. This is not a "raw" representation of the config, but rather an object representation capable of performing actions independently of the underlying configuration version.

func FromBytes

func FromBytes(bytes []byte, options ...Option) (*Config, error)

FromBytes reads a configuration file from the specified byte slice and returns a configuration object.

func FromFile

func FromFile(file string, options ...Option) (*Config, error)

FromFile reads a configuration file from the specified path and returns a configuration object. This will implicitly set the "root" of the path to be the directory containing the file.

func FromReader

func FromReader(r io.Reader, options ...Option) (*Config, error)

FromReader reads a configuration file from the specified reader and returns a configuration object.

type Mode

type Mode string

Mode is the type of template system being used for the output.

const (
	// ModeText is the mode for text-based output.
	ModeText Mode = "text"

	// ModeHTML is the mode for HTML-based output.
	ModeHTML Mode = "html"
)

type Option

type Option = opts.Option

Option is an interface for composable optins that can be provided to configuration objects that can be read.

func WithOutputDir

func WithOutputDir(dir string) Option

WithOutputDir sets the output directory where generated output will be written.

func WithRootDir

func WithRootDir(dir string) Option

WithRootDir sets the root directory which all configuration paths will be considered relative to.

type Package

type Package struct {
	// Name is the name of the package (mandatory).
	Name string

	// Version is a version string for the package version (mandatory).
	Version string

	// Path is an optional path to specify to where the package is located.
	// If specified, this will override the package being fetched from the
	// package registry.
	Path string
}

Package is the source package that will be used as input for the generation.

type Transform

type Transform struct {
	// Include is a list of filters for conditions that an entity may satisfy to
	// be included in the transformation. At least one of these filters must be
	// satisfied for an entity to be included.
	Include []*TransformFilter

	// Exclude is a list of filters for conditions that an entity may satisfy to
	// be excluded from the transformation. If any of these filters are satisfied,
	// the entity will be excluded, even if it satisfies an 'include' filter.
	Exclude []*TransformFilter

	// OutputPath is a template for where the transformation will be output to.
	// The output path is always dynamic, and will be fed each individual entity
	// that has been matched by the filters to be transformed.
	OutputPath string

	// Funcs is mapping of template function-names to files containing templates
	// that will perform textual transformations. This enables more complex logic
	// to be included in template pipelines.
	Funcs map[string]string

	// Templates is a mapping of template names to files containing
	// templates that will be included in the main templates. This enables
	// re-use of common template snippets.
	//
	// Some special templates have implicit meaning in this configuration, but
	// this is otherwise freeform:
	//
	// - 'header': This template will be included at the top of the output file.
	// - 'footer': This template will be included at the bottom of the output file.
	// - 'type': This template will be called with each _individual entity_ 'type'
	//    that is matched by the filters.
	// - 'code-system': This template will be called with each _individual entity_
	//   'code-system' that is matched by the filters.
	// - 'main': This template will be called by the _list of all matched entities_.
	//   This template is provided by default by the implementation, which will call
	//   'header', followed by the appropriate intermediate template, followed by
	//   'footer'. Replacing this will replace all the above templates.
	Templates map[string]string
}

Transform is a configuration for transforming input entities into templated output(s).

type TransformFilter

type TransformFilter struct {
	// Name is a filter on the name of the input entity.
	// This may be a regular expression.
	Name string

	// Type is the type of the input entity.
	Type string

	// URL is an exact-match filter on the URL of the input entity.
	URL string

	// Package is a filter on the package-name of the input entity.
	// This is only relevant if 'input.include-dependencies' is enabled.
	Package string

	// Source is a filter on the source-file that the input entity is defined in.
	// This may be a regular expression.
	Source string

	// Condition is a custom, template-filter that the input entity must satisfy.
	// This is meant as a back-door to allow for more complex conditions than
	// the other filters allow.
	Condition string
}

Directories

Path Synopsis
internal
cfg
Package cfg provides shared configuration that are used across different versions of Fhenix configurations.
Package cfg provides shared configuration that are used across different versions of Fhenix configurations.
cfg/v1
Package cfg contains the raw config data as is parsed directly from YAML.
Package cfg contains the raw config data as is parsed directly from YAML.
opts
Package opts provides default option configuration used internally for configuration dispatching.
Package opts provides default option configuration used internally for configuration dispatching.

Jump to

Keyboard shortcuts

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