env

package
v0.0.0-...-319e03c Latest Latest
Warning

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

Go to latest
Published: Jul 21, 2023 License: GPL-3.0 Imports: 2 Imported by: 0

Documentation

Overview

Package env implements functions for turning config values that are parameterized by the environment string or environment variables into unambiguous, concrete files, paths, and packages.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ValidateKey

func ValidateKey(key string) bool

ValidateKey will determine if a key can be split into valid regexp fields.

Types

type Environment

type Environment []string

An Environment is a sequence of fields specified by an environment string.

func NewEnvironment

func NewEnvironment(env string) Environment

NewEnvironment returns an Environment from an environment string `env`. The environment string has fields separated by spaces.

func (Environment) Matches

func (env Environment) Matches(s string) bool

Matches returns if the passed string s matches the environment as a bool.

func (Environment) Select

func (env Environment) Select(keys []string) (key string, fields []string)

Select determines which key in a slice of strings `keys` matches the environment. A key is a string of regular expressions that may match any field in the environment separated by spaces. The first key that matches the environment will be returned, or an empty string otherwise. The fields that matched the key in the order that they were matched are also returned as a slice.

Note that it's possible for the empty returned string to actually be the matched key itself. This is because an entirely whitespace key acts as a wildcard that matches if no other non-wildcard keys match.

type Match

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

A Match is the result of an environment matching a key. The subgroups in the match are used to replace the contents of other strings.

func NewMatch

func NewMatch(key string, fields []string) Match

NewMatch builds a Match from the key and fields returned from the Select method run from an Environment. Since the returned values should be from the Select method which returns already valid arguments, an invalid key string will panic.

func (Match) Replace

func (m Match) Replace(s string) string

Replace will substitute all of the subgroup matches syntax in the string s.

Jump to

Keyboard shortcuts

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