Created
September 2, 2015 20:06
-
-
Save ptrelford/ec8f8592e74586b26929 to your computer and use it in GitHub Desktop.
Go program to list versions of specified Nuget package
This file contains 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 "os" | |
import "fmt" | |
import "net/http" | |
import "io/ioutil" | |
import "encoding/json" | |
func getVersions(name string) []string { | |
url := fmt.Sprintf("https://www.nuget.org/api/v2/package-versions/%s",name) | |
resp, _ := http.Get(url) | |
defer resp.Body.Close() | |
body, _ := ioutil.ReadAll(resp.Body) | |
var versions []string | |
json.Unmarshal(body, &versions) | |
return versions | |
} | |
func main() { | |
if len(os.Args) < 2 { | |
fmt.Print("Please specify a Nuget package") | |
return | |
} | |
name := os.Args[1] | |
versions := getVersions(name) | |
for _,version := range versions { | |
fmt.Println(version) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment