Created
March 27, 2024 08:19
-
-
Save chopeen/8b2943db321d25d338e20f6283430a2e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package main | |
| import ( | |
| "fmt" | |
| "io" | |
| "net/http" | |
| "os" | |
| ) | |
| func main() { | |
| // fileUrl := "https://registry.ollama.ai/v2/_catalog" | |
| // fileUrl := "https://registry.ollama.ai/v2/ollamaai/ollamaai/manifests/latest" | |
| // fileUrl := "https://ollama.com/token?nonce=SCC4ZwtoS13biPyAADgf_w&scope=repositorylibrarytinyllamapull&service=ollama.com&ts=1711526153" | |
| // fileUrl := "https://dd20bb891979d25aebc8bec07b2b3bbc.r2.cloudflarestorage.com/ollama/docker/registry/v2/blobs/sha256/73/730ebed2578e5be3e25c3ba155b06cb46690426682a38127cb72a9697e4443b4/data?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=66040c77ac1b787c3af820529859349a%2F20240326%2Fauto%2Fs3%2Faws4_request&X-Amz-Date=20240326T182714Z&X-Amz-Expires=1200&X-Amz-SignedHeaders=host&X-Amz-Signature=e11cdf5d0d8804cd0b39e1563a42710c3a6f4b4bd90b9d1ca0e8ade35d445257" | |
| fileUrl := "https://ollama.com/token?nonce=SCC4ZwtoS13biPyAADgf_w&scope=repository" | |
| // Download the file, params: | |
| // 1) name of file to save as | |
| // 2) URL to download FROM | |
| err := DownloadFile("downloaded.txt", fileUrl) | |
| if err != nil { | |
| fmt.Println("Error downloading file: ", err) | |
| return | |
| } | |
| fmt.Println("Downloaded: " + fileUrl) | |
| } | |
| // DownloadFile will download from a given url to a file. It will | |
| // write as it downloads (useful for large files). | |
| func DownloadFile(filepath string, url string) error { | |
| // Get the data | |
| resp, err := http.Get(url) | |
| if err != nil { | |
| return err | |
| } | |
| defer resp.Body.Close() | |
| // Create the file | |
| out, err := os.Create(filepath) | |
| if err != nil { | |
| return err | |
| } | |
| defer out.Close() | |
| // Write the body to file | |
| _, err = io.Copy(out, resp.Body) | |
| return err | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment