config

package
v0.0.0-...-277eb20 Latest Latest
Warning

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

Go to latest
Published: May 28, 2024 License: BSD-3-Clause Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var EmptyEvent = func(value interface{}) (interface{}, error) { return value, nil }

Functions

func AddListener

func AddListener(key string, callback func())

AddListener adds a listener for changes to the given config key that calls the given callback function. Client code is responsible for calling NotifyListeners to signal config changes to listeners.

func KnownOption

func KnownOption(rule Option) bool

func NotifyListeners

func NotifyListeners(key string)

NotifyListeners notifies listeners that the given config key has changed.

func RegisterOption

func RegisterOption(key string, t Type, defaultValue interface{})

Registers a config option without get/set events.

func RegisterOptionWithEvents

func RegisterOptionWithEvents(key string, t Type, defaultValue interface{}, get, set Event)

Registers a config option with get/set events.

Types

type Event

type Event func(value interface{}) (interface{}, error)

Event is run when a user tries to set or get a config value via `state config`

type Option

type Option struct {
	Name     string
	Type     Type
	Default  interface{}
	GetEvent Event
	SetEvent Event
	// contains filtered or unexported fields
}

Option defines what a config value's name and type should be, along with any get/set events

func GetOption

func GetOption(key string) Option

GetOption returns a config option, regardless of whether or not it has been registered. Use KnownOption to determine if the returned option has been previously registered.

type Registry

type Registry map[string]Option

type Type

type Type int
const (
	String Type = iota
	Int
	Bool
)

Jump to

Keyboard shortcuts

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