Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/theirish81/yamlref

An easy Golang library to reference and merge multiple YAML files into a main one
https://github.com/theirish81/yamlref

Last synced: 19 days ago
JSON representation

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

Awesome Lists containing this project

README

        

# YamlRef

| Status | Test coverage |
|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------------|
| [![CircleCI](https://dl.circleci.com/status-badge/img/gh/theirish81/yamlRef/tree/main.svg?style=svg)](https://dl.circleci.com/status-badge/redirect/gh/theirish81/yamlRef/tree/main) | 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**:

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

```yaml
externalObject:
externalFoo: externalBar
externalArray:
- a
- b
- c
externalBot:
bot: true
```
Invoking `MergeAndMarshall("main.yaml")` would produce the following output (in []byte):

**outcome**:

```yaml
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.