cfg

package
v0.0.0-...-c9cfaf6 Latest Latest
Warning

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

Go to latest
Published: Jun 5, 2020 License: BSD-3-Clause Imports: 10 Imported by: 0

Documentation

Overview

Package cfg provides structured benchmark configuration.

Index

Constants

View Source
const SectionSeparator = '-'

SectionSeparator separates section levels in key names.

Variables

This section is empty.

Functions

func Write

func Write(w io.Writer, c Configuration) error

Write configuration to the writer w.

Types

type BoolValue

type BoolValue bool

BoolValue is a boolean.

func (BoolValue) String

func (b BoolValue) String() string

type BytesValue

type BytesValue uint64

BytesValue represents bytes.

func (BytesValue) String

func (b BytesValue) String() string

type Configuration

type Configuration []Entry

Configuration is a nested key-value structure. It is a list of entries, where each entry is either a key-value property or a section containing a nested config.

func (Configuration) Validate

func (c Configuration) Validate() error

Validate checks that all entries are valid.

type Entry

type Entry interface {
	Labeled
	Validatable
	// contains filtered or unexported methods
}

Entry is the base type for configuration entries. (Note this is a sealed interface, it may not be implemented outside this package.)

type Float64Value

type Float64Value float64

Float64Value is a double-precision floating point.

func (Float64Value) String

func (x Float64Value) String() string

type FrequencyValue

type FrequencyValue float64

FrequencyValue represents frequency in Hz.

func (FrequencyValue) String

func (f FrequencyValue) String() string

type Generator

type Generator interface {
	Configuration() (Configuration, error)
}

Generator generates Configuration.

type GeneratorFunc

type GeneratorFunc func() (Configuration, error)

GeneratorFunc adapts a function to the Generator interface.

func (GeneratorFunc) Configuration

func (g GeneratorFunc) Configuration() (Configuration, error)

Configuration calls g.

type IntValue

type IntValue int

IntValue is an integer.

func (IntValue) String

func (x IntValue) String() string

type Key

type Key string

Key is an identifier for a config property or section.

func (Key) Validate

func (k Key) Validate() error

Validate that the key conforms to the Go Benchmark Data Format.

Reference: https://github.com/golang/proposal/blob/d74d825331d9b16ee286ea77c0e4caeaf0efbe30/design/14313-benchmark-format.md#L101-L110

A configuration line is a key-value pair of the form

	key: value

where key begins with a lower case character (as defined by `unicode.IsLower`),
contains no space characters (as defined by `unicode.IsSpace`)
nor upper case characters (as defined by `unicode.IsUpper`),
and one or more ASCII space or tab characters separate “key:” from “value.”
Conventionally, multiword keys are written with the words
separated by hyphens, as in cpu-speed.

type Labeled

type Labeled interface {
	Key() Key
	Doc() string
}

Label for a configuration property or section.

func Label

func Label(k Key, doc string) Labeled

type PercentageValue

type PercentageValue float64

PercentageValue represents a percentage, therefore must be in the range 0 to 100.

func (PercentageValue) String

func (p PercentageValue) String() string

func (PercentageValue) Validate

func (p PercentageValue) Validate() error

Validate checks the p is between 0 and 100.

type PropertyEntry

type PropertyEntry struct {
	Labeled
	Value Value
	Tags  []Tag
}

func KeyValue

func KeyValue(k Key, v Value, tags ...Tag) PropertyEntry

KeyValue builds an undocumented property.

func PerfProperty

func PerfProperty(k Key, doc string, v Value, tags ...Tag) PropertyEntry

PerfProperty builds a property tagged as performance critical.

func Property

func Property(k Key, doc string, v Value, tags ...Tag) PropertyEntry

func (PropertyEntry) Validate

func (p PropertyEntry) Validate() error

Validate the property conforms to the Go Benchmark Data Format. This checks the key as well as the value, as described below.

Reference: https://github.com/golang/proposal/blob/d74d825331d9b16ee286ea77c0e4caeaf0efbe30/design/14313-benchmark-format.md#L111-L113

There are no restrictions on value, except that it cannot contain a newline character.
Value can be omitted entirely, in which case the colon must still be
present, but need not be followed by a space.

In addition, if the property value is Validatable, its Validate method will be called.

type Provider

type Provider interface {
	Labeled
	Generator
	Available() bool
}

Provider is a source of configuration.

func NewProvider

func NewProvider(k Key, doc string, g Generator) Provider

NewProvider builds a Provider from a Generator.

func NewProviderFunc

func NewProviderFunc(k Key, doc string, f func() (Configuration, error)) Provider

NewProviderFunc builds a Provider from a function.

type Providers

type Providers []Provider

Providers is a list of providers.

func (Providers) Available

func (p Providers) Available() bool

Available returns true. Note that sub-providers will be checked for availability when Configuration() is called.

func (Providers) Configuration

func (p Providers) Configuration() (Configuration, error)

Configuration gathers configuration from all providers.

func (Providers) FilterAvailable

func (p Providers) FilterAvailable() Providers

FilterAvailable returns the available sub-providers.

func (Providers) Keys

func (p Providers) Keys() []string

Keys returns all keys in the provider list.

func (Providers) Select

func (p Providers) Select(keys ...string) (Providers, error)

Select returns the subset of providers with the given keys.

type SectionEntry

type SectionEntry struct {
	Labeled
	Sub Configuration
}

SectionEntry is a nested configuration.

func Section

func Section(k Key, doc string, entries ...Entry) SectionEntry

func (SectionEntry) Available

func (s SectionEntry) Available() bool

Available returns true (satisfies the Provider interface).

func (SectionEntry) Configuration

func (s SectionEntry) Configuration() (Configuration, error)

Configuration satisfies the Provider interface.

func (SectionEntry) Validate

func (s SectionEntry) Validate() error

Validate confirms the section key and sub-configuration are valid.

type StringValue

type StringValue string

StringValue is a string constant.

func (StringValue) String

func (s StringValue) String() string

type StringsValue

type StringsValue []string

StringsValue is a list of strings.

func (StringsValue) String

func (s StringsValue) String() string

type Tag

type Tag string

Tag for a configuration property.

const (
	TagNone         Tag = ""
	TagPerfCritical Tag = "perf"
)

Standard tag defintions.

func ParseValueTags

func ParseValueTags(s string) (string, []Tag)

ParseValueTags parses tags from a configuration line value.

func (Tag) Validate

func (t Tag) Validate() error

Validate that tag has the allowed form. Must meet the same requirements as a key, and in addition may not contain square brackets or commas.

type TemperatureValue

type TemperatureValue float64

TemperatureValue is a temperature in celsius.

func (TemperatureValue) String

func (t TemperatureValue) String() string

type TimeValue

type TimeValue time.Time

TimeValue is a time.

func (TimeValue) String

func (t TimeValue) String() string

type Validatable

type Validatable interface {
	Validate() error
}

Validatable is something that can be validated.

type Value

type Value interface {
	String() string
}

Value is a configuration value.

Jump to

Keyboard shortcuts

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