Skip to content

lispad/yaml

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

YAML support for the Go language

Introduction

This yaml package uses https://gopkg.in/yaml.v2, and adds support for Symfony's yaml extension for importing a sub-configuration tree.

Compatibility

This yaml package supports most of YAML 1.1 and 1.2, the same as https://gopkg.in/yaml.v2 does.

This yaml package partially supports Symfony's yaml extension for importing configurations without parameters section and %parameter% macros support.

Installation and usage

The import path for the package is github.com/lispad/yaml.

To install it, run:

go get github.com/lispad/yaml

API documentation

Original's package API documentation:

Symfony's configuration import documentation:

API stability

The package is provided without warranties or conditions of any kind.

Example

There are 3 config files: configs/config1.yaml

imports:
  - {resource: config2.yaml}

a: config1, final value
b:
  d:
    f: 314
  g: 1

configs/config2.yaml

imports:
  - {resource: subdir/config3.yaml}
  - {resource: wrong_file.yaml, ignore_errors: true}

a: config2, will be overriden again
b:
  c: C value from config 2

configs/subdir/config3.yaml

a: config3, will be overriden twice
b:
  c: will be overriden once
  d:
    e: will not be overriden
    f: 1054
  g: 3
package main

import (
	"fmt"
	"log"

	"github.com/lispad/yaml"
)

type T struct {
	A string
	B struct {
		C string
		D struct {
			E string
			F int
		}
		RenamedG int `yaml:"g"`
	}
}

func main() {
	t := T{}

	err := yaml.ProcessFileWithImports("configs/config1.yaml", &t)
	if err != nil {
		log.Fatalf("error: %v", err)
	}
	fmt.Printf("%+v\n\n", t)

	err = yaml.ProcessFileWithImports("wrong_file.yaml", &t)
	if err != nil {
		log.Fatalf("error: %v", err)
	}
}

This example will generate the following output:

{A:config1, final value B:{C:C values from config 2 D:{E:will not be overriden F:314} RenamedG:1}}

error: open wrong_file.yaml: no such file or directory

About

Package implements YAML support with extension for importing a sub-configuration tree for the Go language.

Resources

License

Stars

2 stars

Watchers

1 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages