https://github.com/esakat/dig-yaml
easy to get value of yaml with golang
https://github.com/esakat/dig-yaml
golang yaml
Last synced: 5 months ago
JSON representation
easy to get value of yaml with golang
- Host: GitHub
- URL: https://github.com/esakat/dig-yaml
- Owner: esakat
- License: apache-2.0
- Created: 2020-01-09T02:53:10.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2020-01-09T03:36:11.000Z (over 6 years ago)
- Last Synced: 2026-01-12T22:43:03.734Z (5 months ago)
- Topics: golang, yaml
- Language: Go
- Size: 9.77 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://github.com/esakat/dig-yaml/actions)
# Easy to get value of yaml
Introduction
------------
The dig-yaml package enables to get value of yaml
Installation and usage
----------------------
To install it, run:
go get github.com/esakat/dig-yaml
Example
-------
```Go
package main
import (
"fmt"
"log"
"gopkg.in/yaml.v2"
"os"
"github.com/esakat/dig-yaml"
)
func main() {
f, err := os.Open("testfile.yml")
defer f.Close()
if err != nil {
log.Fatal(err)
}
dec := yaml.NewDecoder(f)
var y map[interface{}]interface{}
dec.Decode(&y)
// it's like y["hoge"].([]interface{})[0].(map[interface{}]interface{})["key1"]
key1, err := dig_yaml.DigYaml(y, "hoge", 0, "key1")
if err != nil {
log.Fatal(err)
}
// Output: test1
fmt.Println(key1)
}
```
testfile.yml
```yaml
foo: hoge
bar: false
hoge:
- key1: test1
key2: 1
- key1: test2
key2: 2
```