MCPcopy Create free account
hub / github.com/cloudwan/gohan / LoadFile

Function LoadFile

util/util.go:104–123  ·  view source on GitHub ↗

LoadFile loads object from file. suffix of filepath will be used as file type. currently, json and yaml is supported

(filePath string)

Source from the content-addressed store, hash-verified

102//LoadFile loads object from file. suffix of filepath will be
103// used as file type. currently, json and yaml is supported
104func 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

Callers 1

LoadMapFunction · 0.85

Calls 2

GetContentFunction · 0.85
DecodeYAMLLibObjectFunction · 0.85

Tested by

no test coverage detected