yaml

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: May 15, 2019 License: GPL-2.0 Imports: 5 Imported by: 0

README

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/WinnerSoftLab/yaml3"
)

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

Documentation

Overview

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

Source code and other details for the project are available at GitHub:

https://github.com/lispad/yaml

Index

Constants

This section is empty.

Variables

View Source
var WrongDstTypeErr = errors.New("wrong type of dst argument: only pointer to struct is supported")

Functions

func ProcessFileWithImports

func ProcessFileWithImports(configPath string, dst interface{}) error

ProcessFileWithImports processes config file and all it's imports tree Currently only pointer to struct is supported as dst argument Need to implement map merging(current version does full override) to support Map dst

Types

type ReadFileFunc

type ReadFileFunc func(filename string) ([]byte, error)

Jump to

Keyboard shortcuts

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