Skip to content

Instantly share code, notes, and snippets.

@ptrelford
Created September 2, 2015 20:07
Show Gist options
  • Save ptrelford/106660d64a1d866294db to your computer and use it in GitHub Desktop.
Save ptrelford/106660d64a1d866294db to your computer and use it in GitHub Desktop.
Go program to download the specified package from Nuget
package main
import "os"
import "fmt"
import "net/http"
import "io"
func downloadPackage(name string) {
url := fmt.Sprintf("https://www.nuget.org/api/v2/package/%s",name)
resp, _ := http.Get(url)
defer resp.Body.Close()
file := fmt.Sprintf("%s.nupkg",name)
out, _ := os.Create(file)
defer out.Close()
io.Copy(out, resp.Body)
}
func main() {
if len(os.Args) < 2 {
fmt.Print("Please specify a Nuget package")
return
}
name := os.Args[1]
downloadPackage(name)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment