Skip to content

gofika/yamlutil

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

codecov Build Status go.dev Go Report Card Licenses

yamlutil

golang yaml utils for common use

Basic Usage

Installation

To get the package, execute:

go get github.com/gofika/yamlutil

Example

package main

import (
	"fmt"

	"github.com/gofika/yamlutil"
)

type Foo struct {
	Name  string `yaml:"name"`
	Value int    `yaml:"value"`
}

func main() {
	foo := &Foo{
		Name:  "Jason",
		Value: 100,
	}
	name := "foo.yaml"
	// write struct to file
	err := yamlutil.WriteFile(name, foo)
	if err != nil {
		fmt.Printf("WriteFile failed. err: %s\n", err.Error())
		return
	}
	// read struct from file
	bar, err = yamlutil.ReadFile[Foo](name)
	if err != nil {
		fmt.Printf("ReadFile failed. err: %s\n", err.Error())
		return
	}
	fmt.Printf("bar.Name: %s\n", bar.Name)
	fmt.Printf("bar.Value: %d\n", bar.Value)
}

About

golang yaml utils for common use

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages