Skip to content

Instantly share code, notes, and snippets.

@HokieGeek
Created October 8, 2019 14:09
Show Gist options
  • Save HokieGeek/7b49f70c443e08ebc2ccaa660431c053 to your computer and use it in GitHub Desktop.
Save HokieGeek/7b49f70c443e08ebc2ccaa660431c053 to your computer and use it in GitHub Desktop.
Example of getting download URLs of all components in a given repo in Nexus Repository
package main
import (
"fmt"
"os"
"strings"
"github.com/sonatype-nexus-community/gonexus/rm"
)
func main() {
rm, err := nexusrm.New("http://localhost:8081", "admin", "admin123")
if err != nil {
panic(err)
}
components, err := nexusrm.GetComponents(rm, os.Args[1])
if err != nil {
panic(err)
}
mainAsset := func(assets []nexusrm.RepositoryItemAsset, ext string) string {
for _, a := range assets {
switch {
case strings.HasSuffix(a.DownloadURL, ext):
return a.DownloadURL
}
}
return ""
}
for _, c := range components {
fmt.Println(c.Name)
switch c.Format {
case "rubygems":
fmt.Printf("\t%s\n", mainAsset(c.Assets, ".gem"))
case "maven2":
fmt.Printf("\t%s\n", mainAsset(c.Assets, ".jar"))
default:
fmt.Printf("\t%s\n", c.Assets[0].DownloadURL)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment