Created
October 8, 2019 14:09
-
-
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
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 ( | |
"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