configmap

package
v0.0.0-...-b4aeae5 Latest Latest
Warning

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

Go to latest
Published: Mar 7, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package configmap provides an abstraction for reading and writing config

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Getter

type Getter interface {
	// Get should get an item with the key passed in and return
	// the value. If the item is found then it should return true,
	// otherwise false.
	Get(key string) (value string, ok bool)
}

Getter provides an interface to get config items

type Map

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

Map provides a wrapper around multiple Setter and Getter interfaces.

func New

func New() *Map

New returns an empty Map

func (*Map) AddGetter

func (c *Map) AddGetter(getter Getter, priority Priority) *Map

AddGetter appends a getter onto the end of the getters in priority order

func (*Map) AddSetter

func (c *Map) AddSetter(setter Setter) *Map

AddSetter appends a setter onto the end of the setters

func (*Map) ClearGetters

func (c *Map) ClearGetters(priority Priority) *Map

ClearGetters removes all the getters with the priority given

func (*Map) ClearSetters

func (c *Map) ClearSetters() *Map

ClearSetters removes all the setters set so far

func (*Map) Get

func (c *Map) Get(key string) (value string, ok bool)

Get gets an item with the key passed in and return the value from the first getter. If the item is found then it returns true, otherwise false.

func (*Map) GetPriority

func (c *Map) GetPriority(key string, maxPriority Priority) (value string, ok bool)

GetPriority gets an item with the key passed in and return the value from the first getter to return a result with priority <= maxPriority. If the item is found then it returns true, otherwise false.

func (*Map) Set

func (c *Map) Set(key, value string)

Set sets an item into all the stored setters.

type Mapper

type Mapper interface {
	Getter
	Setter
}

Mapper provides an interface to read and write config

type Priority

type Priority int8

Priority of getters

const (
	PriorityNormal  Priority = iota
	PriorityConfig           // use for reading from the config
	PriorityDefault          // use for default values
	PriorityMax
)

Priority levels for AddGetter

type Setter

type Setter interface {
	// Set should set an item into persistent config store.
	Set(key, value string)
}

Setter provides an interface to set config items

type Simple

type Simple map[string]string

Simple is a simple Mapper for testing

func (Simple) Decode

func (c Simple) Decode(in string) error

Decode an Encode~d string in into c

func (Simple) Encode

func (c Simple) Encode() (string, error)

Encode from c into a string suitable for putting on the command line

func (Simple) Get

func (c Simple) Get(key string) (value string, ok bool)

Get the value

func (Simple) Set

func (c Simple) Set(key, value string)

Set the value

func (Simple) String

func (c Simple) String() string

String the map value the same way the config parser does, but with sorted keys for reproducibility.

Jump to

Keyboard shortcuts

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