keys

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2019 License: MIT Imports: 4 Imported by: 3

README

keys

A library of functions that perform transforms on keys for config.

GoDoc

Documentation

Overview

Package keys provides utilities to manipulate key strings.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsArrayLen

func IsArrayLen(key string) (string, bool)

IsArrayLen determines if the key corresponds to an array length. i.e. is of the form a[]. If so IsArrayLen returns true and the name of the array.

func ParseArrayElement

func ParseArrayElement(key string) (string, []int)

ParseArrayElement determines if the key corresponds to an array element. i.e. is of the form a[i]. Returns the name of the array and the a list of indicies into the array.

Types

type Replacer

type Replacer interface {
	Replace(string) string
}

Replacer maps a key from one space to another.

type ReplacerFunc

type ReplacerFunc func(key string) string

ReplacerFunc is a func that implements a string replacement.

func CamelCaseReplacer

func CamelCaseReplacer() ReplacerFunc

CamelCaseReplacer is a replacer that that forces keys to camel case, so each word begins with a capital letter. Words are separated by the default separator - ".".

func CamelCaseSepReplacer

func CamelCaseSepReplacer(sep string) ReplacerFunc

CamelCaseSepReplacer is a replacer that that forces keys to camel case, so each word begins with a capital letter. Words are separated by the provided separator.

func ChainReplacer

func ChainReplacer(rr ...ReplacerFunc) ReplacerFunc

ChainReplacer returns a replacer that applies a list of replacers, in order.

func LowerCamelCaseReplacer

func LowerCamelCaseReplacer() ReplacerFunc

LowerCamelCaseReplacer is a replacer that that forces keys to camel case, so each word begins with a capital letter, except the first word which is all lower case. Words are separated by the default separator - ".".

func LowerCamelCaseSepReplacer

func LowerCamelCaseSepReplacer(sep string) ReplacerFunc

LowerCamelCaseSepReplacer is a replacer that that forces keys to camel case, so each word begins with a capital letter, except the first word which is all lower case. Words are separated by the provided separator.

func LowerCaseReplacer

func LowerCaseReplacer() ReplacerFunc

LowerCaseReplacer is a replacer that that forces keys to lower case.

func NullReplacer

func NullReplacer() ReplacerFunc

NullReplacer is a replacer that leaves a key unchanged. This can be used to override the mapping in Getters that assume a default mapping if none (Replacer(nil)) is provided.

func PrefixReplacer

func PrefixReplacer(prefix string) ReplacerFunc

PrefixReplacer adds a prefix to keys. This can be used to logically move the root of a Getter to a node of the config space.

func StringReplacer

func StringReplacer(old, new string) ReplacerFunc

StringReplacer replaces one string in the key with another. The ols is replaced with the new using strings.Replace. This is typically used to replace tier separators, e.g. "." in config space with "_" in env space, but can also be used for arbitrary substitutions.

func UpperCaseReplacer

func UpperCaseReplacer() ReplacerFunc

UpperCaseReplacer forces keys to upper case.

func (ReplacerFunc) Replace

func (r ReplacerFunc) Replace(key string) string

Replace calls the ReplacerFunc to perform the map.

Jump to

Keyboard shortcuts

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