config

package
v0.0.23 Latest Latest
Warning

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

Go to latest
Published: Jan 25, 2024 License: MIT Imports: 0 Imported by: 0

README

configreader allows using different types of config files with the app.

the JSON and YAML configreaders duplicate a ton of code

Differences:

  • JSON can only unmarshal into map[string]interface{} while YAML can only unmarshal into map[interface{}]interface{}.
  • JSON can only parse float64s, while YAML can also produce ints

ConfigReader Error Cases

These need to be added to get configs working well enough :)

config not passed -> flag not set config passed, file doesn't exist -> flag not set # command should error if a flag isn't set properly config passed, file exists, can't unmarshall -> ERROR config passed, file exists, can unmarshall, invalid path-> ERROR config passed, file exists, can unmarshall, valid path, path not in config -> flag not set config passed, file exists, can unmarshall, valid path, path in config, value error -> ERROR config passed, file exists, can unmarshall, valid path, path in config, value created -> flag set

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type NewReader

type NewReader func(filePath string) (Reader, error)

NewReader constructs a ConfigReader

type Reader

type Reader interface {
	Search(path string) (*SearchResult, error)
}

Reader searches with a path to try to get a config value. if the result is nil, nil, it means the result wasn't found

type SearchResult

type SearchResult struct {
	// IFace holds the value if found
	IFace interface{}
	// IsAggregated indicates whether the value was stitched together from child config elements
	// For example, consider a config with the following content: {"subreddits": [{"name": "earthporn"}, {"name": "wallpapers"}]}
	// We can get all the names with a path like "subreddits[].name". These results are aggregated into a list, and IsAggregated will be set to true
	IsAggregated bool
}

SearchResult is the result of trying to search through a config for a value

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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