2019-03-21 18:08:38 +00:00
|
|
|
package front_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"log"
|
|
|
|
|
2019-05-25 19:14:09 +00:00
|
|
|
"christine.website/internal/front"
|
2019-03-21 18:08:38 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var markdown = []byte(`---
|
|
|
|
title: Ferrets
|
|
|
|
authors:
|
|
|
|
- Tobi
|
|
|
|
- Loki
|
|
|
|
- Jane
|
|
|
|
---
|
|
|
|
Some content here, so
|
|
|
|
interesting, you just
|
|
|
|
want to keep reading.`)
|
|
|
|
|
|
|
|
type article struct {
|
|
|
|
Title string
|
|
|
|
Authors []string
|
|
|
|
}
|
|
|
|
|
|
|
|
func Example() {
|
|
|
|
var a article
|
|
|
|
|
|
|
|
content, err := front.Unmarshal(markdown, &a)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatalf("error unmarshalling: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Printf("%#v\n", a)
|
|
|
|
fmt.Printf("%s\n", string(content))
|
|
|
|
// Output:
|
|
|
|
// front_test.article{Title:"Ferrets", Authors:[]string{"Tobi", "Loki", "Jane"}}
|
|
|
|
//
|
|
|
|
// Some content here, so
|
|
|
|
// interesting, you just
|
|
|
|
// want to keep reading.
|
|
|
|
}
|