config

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Aug 8, 2022 License: ISC Imports: 11 Imported by: 0

Documentation

Overview

Package config provides access to Fairu configuration file.

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidConfig       = errors.New("invalid configuration value")
	ErrInvalidConfigGroup  = fmt.Errorf("%w: unknown configuration group", ErrInvalidConfig)
	ErrInvalidConfigMap    = fmt.Errorf("%w: a map is expected", ErrInvalidConfig)
	ErrInvalidConfigOption = fmt.Errorf("%w: an invalid option was provided", ErrInvalidConfig)
	ErrInvalidConfigString = fmt.Errorf("%w: a string is expected", ErrInvalidConfig)
)

Errors when reading the configuration.

Functions

func GetConfigFile

func GetConfigFile() (string, error)

GetConfigFile gets the default path of the configuration file.

Types

type Action

type Action struct {
	Action    action.Action
	Arguments []string
}

Action contains a action and its arguments.

func (Action) Call

func (a Action) Call(path string) string

Call calls the action with its arguments on the specified path.

type Config

type Config struct {
	Variables map[string]string `yaml:"Variables"`
	Rules     []Rule            `yaml:"Rules"`
	Options   Options           `yaml:"Options"`
}

Config contains the configuration of Fairu.

func Load

func Load() (*Config, error)

Load loads the configuration from the default configuration file.

func ReadConfig

func ReadConfig(r io.Reader) (*Config, error)

ReadConfig reads the configuration from a io.Reader.

Example
package main

import (
	"fmt"
	"os"

	"github.com/anderson-lt/fairu/config"
)

func main() {
	file, err := os.Open("testdata/example_config.yaml")
	if err != nil {
		panic(err)
	}

	config, err := config.ReadConfig(file)
	if err != nil {
		panic(err)
	}

	fmt.Println(config)
}
Output:

<Config: 2 Variables, 4 Rules>

func (*Config) String

func (c *Config) String() string

func (*Config) UnmarshalYAML added in v0.2.0

func (c *Config) UnmarshalYAML(node *yaml.Node) error

UnmarshalYAML implements yaml.Unmarshaler.

type Filter

type Filter struct {
	Filter    filter.Filter
	Arguments []string
}

Filter contains a filter and its arguments.

func (Filter) Call

func (f Filter) Call(path string) bool

Call calls the filter with its arguments on the specified path.

type Options

type Options struct {
}

Options contains the options of the Fairu.

type Rule

type Rule struct {
	Name    string
	Filters []Filter
	Actions []Action
}

Rule represents a rule in the configuration.

func (Rule) Accept

func (r Rule) Accept(path string) bool

Accept apply all the filters with your arguments on the specified path.

func (Rule) Execute

func (r Rule) Execute(path string)

Execute executes every action on the specified path.

func (*Rule) UnmarshalYAML

func (r *Rule) UnmarshalYAML(node *yaml.Node) error

UnmarshalYAML implements yaml.Unmarshaler.

Jump to

Keyboard shortcuts

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