Skip to content

Latest commit

 

History

History
40 lines (29 loc) · 888 Bytes

unmarshalling_yaml.md

File metadata and controls

40 lines (29 loc) · 888 Bytes

Unmarshalling a YAML file

Grabana provides a way to unmarshal YAML. This can be done by giving a file or anything that satisfies the io.Reader interface to the decoder.UnmarshalYAML function.

The result is a dashboard.Builder that can then be used by Grabana's client to upsert the dashboard.

package main 

import (
	"bytes"
	"fmt"
	"os"

	"github.com/K-Phoen/grabana/decoder"
)

func main() {
	filePath := "some/awesome/dashboard.yaml"

	content, err := os.ReadFile(filePath)
	if err != nil {
		fmt.Fprintf(os.Stderr, "Could not read file: %s\n", err)
		os.Exit(1)
	}

	dashboard, err := decoder.UnmarshalYAML(bytes.NewBuffer(content))
	if err != nil {
		fmt.Fprintf(os.Stderr, "Could not parse file: %s\n", err)
		os.Exit(1)
	}

	// do something with `dashboard`
}

That was it!

Return to the index to explore the other possibilities of the module