LoadTemplate loads object from file. suffix of filepath will be used as file type. currently, json and yaml is supported
(filePath string, params interface{})
| 125 | //LoadTemplate loads object from file. suffix of filepath will be |
| 126 | // used as file type. currently, json and yaml is supported |
| 127 | func LoadTemplate(filePath string, params interface{}) (map[string]interface{}, error) { |
| 128 | templateSource, err := GetContent(filePath) |
| 129 | t := template.Must(template.New("tmpl").Parse(string(templateSource[:]))) |
| 130 | outputBuffer := bytes.NewBuffer(make([]byte, 0, 100)) |
| 131 | t.Execute(outputBuffer, params) |
| 132 | data := outputBuffer.Bytes() |
| 133 | if err != nil { |
| 134 | return nil, err |
| 135 | } |
| 136 | if strings.HasSuffix(filePath, ".json") { |
| 137 | var document map[string]interface{} |
| 138 | err = json.Unmarshal(data, &document) |
| 139 | return document, err |
| 140 | } else if strings.HasSuffix(filePath, ".yaml") { |
| 141 | var documentYAML map[interface{}]interface{} |
| 142 | err = yaml.Unmarshal(data, &documentYAML) |
| 143 | if err != nil { |
| 144 | return map[string]interface{}{}, err |
| 145 | } |
| 146 | document := DecodeYAMLLibObject(documentYAML) |
| 147 | return document.(map[string]interface{}), nil |
| 148 | } |
| 149 | return nil, err |
| 150 | } |
| 151 | |
| 152 | //DecodeYAMLLibObject decodes interface format |
| 153 | //yaml.v2 lib returns map as map[interface{}]interface{} while gohan lib uses map[string]interface{} |
no test coverage detected