Skip to content

An easy Golang library to reference and merge multiple YAML files into a main one

License

Notifications You must be signed in to change notification settings

theirish81/yamlRef

Repository files navigation

YamlRef

Status Test coverage
CircleCI 92.1%

An easy Golang library to reference and merge multiple local YAML files into a main one.

$ref links

To perform the replacement, use a "$ref string" as value in any item of your YAML as in:

  • $ref:file://external.yaml: replace this $ref string with the value of the external.yaml file, located in the same directory as the main file
  • $ref:file:///home/theirish81/external.yaml replace this $ref with the value of the external.yaml file, located in an absolute path
  • $ref:file://external.yaml?comp=externalBot replace this $ref with a specific object externalBot (root level only) described in the external.yaml file, located in the same directory as the main file

Example

main.yaml:

rootObject:
  foo: bar
  extRef: "$ref:file://external1.yaml"
  myArray:
    - foo
    - bar
    - "$ref:file://external1.yaml?comp=externalBot"

external1.yaml:

externalObject:
  externalFoo: externalBar
  externalArray:
    - a
    - b
    - c
externalBot:
  bot: true

Invoking MergeAndMarshall("main.yaml") would produce the following output (in []byte):

outcome:

rootObjct:
  extRef:
    externalBot:
      bot: true
    externalObject:
      externalArray:
        - a
        - b
        - c
      externalFoo: externalBar
  foo: bar
  myArray:
    - foo
    - bar
    - bot: true

You can also invoke the Merge(path string) function to obtain the unmarshalled data structure.

About

An easy Golang library to reference and merge multiple YAML files into a main one

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published

Languages