Skip to content

lunixbochs/matter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GoDoc Build Status

matter

A Go library for easily reading/writing files with frontmatter.

What is frontmatter?

Files with YAML frontmatter attached usually look like this:

---
key: value
key: value
---
regular file contents.

Installation

go get github.com/lunixbochs/matter

Example

package main

import (
    "fmt"
    "log"

    "github.com/lunixbochs/matter"
)

type TestStruct struct {
    Example string
    KeyTwo  string
}

var dataTest = []byte("Example data.")
var structTest = &TestStruct{
    Example: "Eggs",
    KeyTwo:  "Ham",
}

func main() {
    err := matter.WriteYAML("test.yml", structTest, dataTest, 0600)
    if err != nil {
        log.Fatal(err)
    }

    front := &TestStruct{}
    data, err := matter.ReadYAML("test.yml", front)
    if err != nil {
        log.Fatal(err)
    }
    fmt.Println("  frontmatter:", front)
    fmt.Println("  data:", string(data))
}

About

Frontmatter library for Go (YAML and plaintext)

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages