github.com/theliebeskind/genfig@v0.1.5-alpha/parsers/yaml.go (about) 1 package parsers 2 3 import ( 4 "errors" 5 6 yaml "gopkg.in/yaml.v2" 7 ) 8 9 // YamlStrategy parses yaml and json files 10 type YamlStrategy struct { 11 } 12 13 // Parse of YamlStrategy parses yaml and json files into Parsing result 14 func (s *YamlStrategy) Parse(data []byte) (map[string]interface{}, error) { 15 if len(data) == 0 { 16 return nil, errors.New("Empty data") 17 } 18 r := map[string]interface{}{} 19 20 err := yaml.Unmarshal(data, r) 21 if err != nil { 22 return nil, err 23 } 24 25 return r, nil 26 }