GetContent loads file from remote or local
(url string)
| 174 | |
| 175 | //GetContent loads file from remote or local |
| 176 | func 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 |
| 198 | func TempFile(dir string, prefix string, suffix string) (*os.File, error) { |
no test coverage detected