MCPcopy
hub / github.com/betty200744/ultimate-go / GetImage

Function GetImage

build-in-package/http/http.go:52–67  ·  view source on GitHub ↗
(url string)

Source from the content-addressed store, hash-verified

50 return data, nil
51}
52func GetImage(url string) (string, error) {
53 res, errRes := http.Get(url)
54 if errRes != nil {
55 log.Fatal(errRes)
56 }
57 data, errRead := ioutil.ReadAll(res.Body)
58 if errRead != nil {
59 return "", errRead
60 }
61 defer res.Body.Close()
62 filename := "keyboard.jpeg"
63 if res.Header.Get("Content-Type") == "image/jpeg" {
64 ioutil.WriteFile(filename, data, os.ModePerm)
65 }
66 return filename, nil
67}
68func Download(url string) (string, error) {
69 filename := path.Base(url)
70 res, errRes := http.Get(url)

Callers 1

TestGetImageFunction · 0.85

Calls 2

GetMethod · 0.65
CloseMethod · 0.45

Tested by 1

TestGetImageFunction · 0.68