configutil

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Aug 26, 2019 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Copyright (c) 2016-2019 Uber Technologies, Inc.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Package configutil provides an interface for loading and validating configuration data from YAML files.

Other YAML files could be included via the following directive:

production.yaml: extends: base.yaml

There is no multiple inheritance supported. Dependency tree suppossed to form a linked list.

Values from multiple configurations within the same hierarchy are deep merged

Note regarding configuration merging:

Array defined in YAML will be overriden based on load sequence.
e.g. in the base.yaml:
     sports:
        - football
     in the development.yaml:
     extends: base.yaml
     sports:
        - basketball
     after the merge:
     sports:
        - basketball  // only keep the latest one

Map defined in YAML will be merged together based on load sequence.
e.g. in the base.yaml:
     sports:
        football: true
     in the development.yaml:
     extends: base.yaml
     sports:
        basketball: true
     after the merge:
     sports:  // combine all the map fields
        football: true
        basketball: true

Index

Constants

This section is empty.

Variables

View Source
var ErrCycleRef = errors.New("cyclic reference in configuration extends detected")

ErrCycleRef is returned when there are circular dependencies detected in configuraiton files extending each other.

Functions

func Load

func Load(filename string, config interface{}) error

Load loads configuration based on config file name. It will follow extends directives and do a deep merge of those config files.

Types

type Extends

type Extends struct {
	Extends string `yaml:"extends"`
}

Extends define a keywoword in config for extending a base configuration file.

type ValidationError

type ValidationError struct {
	// contains filtered or unexported fields
}

ValidationError is the returned when a configuration fails to pass validation.

func (ValidationError) ErrForField

func (e ValidationError) ErrForField(name string) error

ErrForField returns the validation error for the given field.

func (ValidationError) Error

func (e ValidationError) Error() string

Error implements the `error` interface.

Jump to

Keyboard shortcuts

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