LoadFile loads object from file. suffix of filepath will be used as file type. currently, json and yaml is supported
(filePath string)
| 102 | //LoadFile loads object from file. suffix of filepath will be |
| 103 | // used as file type. currently, json and yaml is supported |
| 104 | func LoadFile(filePath string) (interface{}, error) { |
| 105 | bodyBuff, err := GetContent(filePath) |
| 106 | if err != nil { |
| 107 | return nil, err |
| 108 | } |
| 109 | if strings.HasSuffix(filePath, ".json") { |
| 110 | var document interface{} |
| 111 | err = json.Unmarshal(bodyBuff, &document) |
| 112 | return document, err |
| 113 | } else if strings.HasSuffix(filePath, ".yaml") || strings.HasSuffix(filePath, ".yml") { |
| 114 | var documentYAML interface{} |
| 115 | err = yaml.Unmarshal(bodyBuff, &documentYAML) |
| 116 | if err != nil { |
| 117 | return map[string]interface{}{}, err |
| 118 | } |
| 119 | document := DecodeYAMLLibObject(documentYAML) |
| 120 | return document, nil |
| 121 | } |
| 122 | return nil, err |
| 123 | } |
| 124 | |
| 125 | //LoadTemplate loads object from file. suffix of filepath will be |
| 126 | // used as file type. currently, json and yaml is supported |
no test coverage detected