Documentation
¶
Overview ¶
Jsonconfig implements configuration, reading json into an ice Module.
To use:
1) Create the Schema. List your configurable Implementations. Each Implementations can be backed by several named Implementations.
- Options.Parse parses bytes and creates a Configuration. a) for each Implementations, pick which Implementation. b) json.Unmarshal the json into that Implementation c) Implementation can now be used as a Module or json.Marshal'ed to print its configuration
- Configuration is an ice Module that installs each Implementation
Example: 1) Create the Schema
schema := jsonconfig.Schema(map[string]jsonconfig.Implementations{ "Storage": { "foo": StorageFooConfig{}, "baz": StorageBazConfig{}, "": StorageFooConfig{Type: "foo", Param: 17}, }, "Cluster": { "bar": ClusterBarConfig{}, "quuz": ClusterQuuxConfig{}, } }
2) Parse
mod, _ := schema.Parse([]byte(`{ "Storage": { "Type": "FooStorage", "FooArg": "Val" }, "Cluster": { "Type": "BarCluster", "BarArg": 17 } }`)
3) Install the Confniguration
bag.InstallModule(mod)
Notes ¶
Right now, that's an oddity that config's should be unset except the default, which should be. It would be better if we solved this.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetConfigText ¶
GetConfigText finds the right text for a configFlag. If configFlag looks like a filename (of the form foo.bar where foo and bar are just alphanumeric), read it as an asset. This filename can optionally have appended json (foo.bar.<json>) to override the file. Otherwise, assume it's the literal json text.
Types ¶
type Configuration ¶
func (Configuration) Install ¶
func (c Configuration) Install(bag *ice.MagicBag)
Configuration is itself a Module, that installs each Impl as a Module (in Design Patterns terminology, it's a Composite)
type Implementation ¶
type Implementations ¶
type Implementations map[string]Implementation
Implementations maps the the names of implementations to the Implementation As a special case, "" maps to a default implementation that will not be unmarshal'ed, and so the Implementation will be used as-is.
type Schema ¶
type Schema map[string]Implementations
Schema holds the different Implementations's the client wants to configure
func EmptySchema ¶
func EmptySchema() Schema
EmptySchema returns an empty Schema, needed if you don't allow configuration