appconf

package
v0.0.0-test-multiarch Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2024 License: GPL-3.0 Imports: 12 Imported by: 0

Documentation

Overview

Package appconf provides runtime configuration.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func LoadIncludes

func LoadIncludes(dir string, dst *Config, includes []string) ([]string, error)

LoadIncludes will go through each include, load the configs, merge the configs, then load any further includes. Returns a list of all files that were loaded.

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

func LoadLocalConfig(dir, file string) (*Config, error)

LoadLocalConfig will load Config from a local file, as well as any included files

Jump to

Keyboard shortcuts

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