dict

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Dec 13, 2022 License: MIT Imports: 3 Imported by: 13

README

dict

GoDoc

The dict package provides a config Getter that retrieves values from a key/value map.

The dict is typically used to define default values.

Example usage:

import (
    "fmt"

    "github.com/warthog618/config"
    "github.com/warthog618/config/dict"
)

func main() {
    d := dict.New()
    d.Set("config.file", "config.json")
    c := config.New(d)
    cfgFile := c.MustGet("config.file").String()
    fmt.Println("config-file:", cfgFile)
    // ....
}

One option can be applied to dict.New:

The WithMap option provides a map to be used instead of creating a new empty map. Not that the dict takes ownership of the map and any subsequent sets will alter the underlying map.

Documentation

Overview

Package dict provides a simple Getter that wraps a key/value map.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Getter

type Getter struct {
	config.GetterAsOption
	// contains filtered or unexported fields
}

Getter is a simple getter that wraps a key/value map. The Getter is mutable, though only by setting keys, and is safe to call from multiple goroutines.

func New

func New(options ...Option) *Getter

New returns a dict Getter. The key/value map is initially empty and must be populated using WithConfig or calls to Set.

func (*Getter) Get

func (r *Getter) Get(key string) (interface{}, bool)

Get returns the value from the dict config.

func (*Getter) Set

func (r *Getter) Set(key string, v interface{})

Set adds a value to the key/value map.

type Option

type Option func(*Getter)

Option is a function which modifies a Getter at construction time.

func WithMap

func WithMap(config map[string]interface{}) Option

WithMap provides the config map, rather than having the Getter create a new one. Note that the Getter assumes ownership of the map, so the caller should not alter the map or any of its mutable values after the call.

Jump to

Keyboard shortcuts

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