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

Function GetContent

util/util.go:176–195  ·  view source on GitHub ↗

GetContent loads file from remote or local

(url string)

Source from the content-addressed store, hash-verified

174
175//GetContent loads file from remote or local
176func GetContent(url string) ([]byte, error) {
177 if strings.HasPrefix(url, "http://") || strings.HasPrefix(url, "https://") {
178 resp, err := http.Get(url)
179 if err != nil {
180 return nil, err
181 }
182 defer resp.Body.Close()
183 content, err := ioutil.ReadAll(resp.Body)
184 return content, err
185 }
186 if strings.HasPrefix(url, "embed://") {
187 url = strings.TrimPrefix(url, "embed://")
188 return Asset(url)
189 }
190 if strings.HasPrefix(url, "file://") {
191 url = strings.TrimPrefix(url, "file://")
192 }
193 content, err := ioutil.ReadFile(url)
194 return content, err
195}
196
197// TempFile creates a temporary file with the specified prefix and suffix
198func TempFile(dir string, prefix string, suffix string) (*os.File, error) {

Callers 3

util_test.goFile · 0.85
LoadFileFunction · 0.85
LoadTemplateFunction · 0.85

Calls 2

GetMethod · 0.65
CloseMethod · 0.65

Tested by

no test coverage detected