Documentation
¶
Overview ¶
Package appconf provides runtime configuration.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Config ¶
type Config struct {
Name string `json:"name,omitempty"`
Metadata *traits.Metadata `json:"metadata,omitempty"`
// Includes lists other files and glob patterns for config to load.
// Files are read in the order specified here then by filepath.Glob.
// Drivers, Automation, and Zones are merged using the Name in a first-come, first-served nature.
// Glob includes are expanded in the output when using LoadLocalConfig, files not found will be excluded.
// Included files that also have includes will be processed once all includes in this config are processed.
// Paths are resolved relative to the directory the config file is in.
// Paths starting with `/` will be treated as absolute paths.
Includes []string `json:"includes,omitempty"`
Drivers []driver.RawConfig `json:"drivers,omitempty"`
Automation []auto.RawConfig `json:"automation,omitempty"`
Zones []zone.RawConfig `json:"zones,omitempty"`
// the path to the file this config was loaded from
FilePath string `json:"-"`
}
Example ¶
type ExampleDriverConfig struct {
driver.BaseConfig
Property string `json:"property"`
}
// language=json
buf := []byte(`{
"drivers": [
{
"name": "foo",
"type": "example",
"property": "bar"
}
]
}`)
var config Config
err := json.Unmarshal(buf, &config)
if err != nil {
panic(err)
}
for _, d := range config.Drivers {
switch d.Type {
case "example":
var exampleConfig ExampleDriverConfig
err := json.Unmarshal(d.Raw, &exampleConfig)
if err != nil {
panic(err)
}
fmt.Printf("ExampleDriver name=%q property=%q\n", d.Name, exampleConfig.Property)
default:
fmt.Printf("unknown driver type %q\n", d.Type)
}
}
Output: ExampleDriver name="foo" property="bar"
func LoadLocalConfig ¶
LoadLocalConfig will load Config from a local file, as well as any included files
Click to show internal directories.
Click to hide internal directories.