Skip to content

Commit

Permalink
Testing YAML Unmarshalling
Browse files Browse the repository at this point in the history
  • Loading branch information
cgxeiji committed Oct 25, 2018
1 parent b65ec0e commit a5f542c
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
45 changes: 45 additions & 0 deletions scholar.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package main

import (
"fmt"
"io/ioutil"
"reflect"

"gopkg.in/yaml.v2"
)

func main() {
test := make(map[interface{}]interface{})

data, err := ioutil.ReadFile("types.yaml")
if err != nil {
panic(err)
}

err = yaml.Unmarshal(data, &test)
if err != nil {
panic(err)
}

for entry, ev := range test {
fmt.Println(entry)
evv := reflect.ValueOf(ev)
if evv.Kind() == reflect.Map {
for _, content := range evv.MapKeys() {
cv := evv.MapIndex(content).Interface()
fmt.Println(" ", content)

cvv := reflect.ValueOf(cv)
if cvv.Kind() == reflect.Map {
for _, field := range cvv.MapKeys() {
fv := cvv.MapIndex(field)
fmt.Println(" ", field, "->", fv)
}
} else {
fmt.Println(" >", cv)
}
}
}
}

}
17 changes: 17 additions & 0 deletions types.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
article:
desc: An article in a journal, magazine, newspaper, or other periodical which forms a self-contained unit with its own title.
req:
author: Author(s) of the article.
title: Title of the article.
journaltitle: Title of the journal.
date: YYYY-MM-DD format.
opt:
editor: Editor(s) of the journal.
language: Language of the article.
series: Series of the journal.
volume: Volume of the journal.
number: Number of the journal.
issn: ISSN number of the article.
doi: DOI code of the article.
url: URL of the article.
urldate: Access date in YYY-MM-DD format.

0 comments on commit a5f542c

Please sign in to comment.