yaml

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2023 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package yaml has some utilities for YAML codec

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func StructToYAML

func StructToYAML(interFace interface{}) (yamlData string, err error)

StructToYAML convert struct to YAML The struct must have yaml tags

:param interFace: The struct data with yaml tags

Example

var a NTP

thing, err := xml.StructToYAML(a)

fmt.Println(thing)

func YAMLToStruct

func YAMLToStruct(interFace interface{}, yamlData string) error

YAMLToStruct convert YAML to a Struct The struct must have yaml tags

:param interFace: A pointer to a variable of the struct data with yaml tags
:param yamlData: The YAML data

Example

type NTP struct {
	NTPServersData struct {
		SourceInterface string `yaml:"source_interface" json:"source_interface" xml:"source_interface"`
		NTPServerKey    []struct {
			IPv4Host string `yaml:"ipv4_host" json:"ipv4_host" xml:"ipv4_host"`
			Priority bool   `yaml:"priority" json:"priority" xml:"priority"`
		} `yaml:"ntp_servers" json:"ntp_servers" xml:"ntp_servers"`
	} `yaml:"ntp" json:"ntp" xml:"ntp"`
}

var a NTP

err := json.YAMLToStruct(&a, ntpYaml)
if err != nil {
	log.Fatal(err)
}

fmt.Println(a)

Types

This section is empty.

Jump to

Keyboard shortcuts

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