
Go-NuGet is a NuGet API v3 client written in Golang, enabling Golang programs to interact with NuGet repositories in a simple and unified way!
Installation ❘ Coverage ❘ Usage ❘ Examples ❘ License
This API client package covers the NuGet API v3 endpoints and is updated regularly to add new and/or missing endpoints. Currently, the following services are supported:
- Service Resources
- Package Search
- Package Metadata
- Package Publish
- Package Delete
- Package Download
- Package Version
- Package Read
- Package Create
- Package Dependencies
- Package Source Configuration
- Package Source Authentication
When used with Go modules, use the following import path:
go get github.com/huhouhua/go-nuget
You can find the docs at go docs.
Construct a new NuGet client, then use the various methods on the client to access different parts of the NuGet API. For example, to get the service resources:
client, err := nuget.NewClient()
if err != nil {
panic(fmt.Sprintf("Failed to create client: %v", err))
}
// Get request resource
index, _, err := client.IndexResource.GetIndex()
if err != nil {
log.Fatalf("Failed to get resources: %v", err)
}
// print the resources url
for _, r := range index.Resources {
fmt.Printf("url: %s", r.Id)
}
There are a few With...
option functions that can be used to customize
the API client. For example, to set a custom source URL:
client, err := nuget.NewClient(
nuget.WithSourceURL("https://your-private-feed.com/v3/index.json"),
nuget.WithRetryMax(5),
nuget.WithRetryWaitMinMax(time.Second*1, time.Second*10),
)
if err != nil {
panic(fmt.Sprintf("Failed to create client: %v", err))
}
The examples directory contains a couple of clear examples, of which one is partially listed here as well:
package main
import (
"fmt"
"github.com/huhouhua/go-nuget"
"log"
"time"
)
func main() {
// Create a new NuGet client with custom retry settings
client, err := nuget.NewClient(
nuget.WithSourceURL("https://your-private-feed.com/v3/index.json"),
nuget.WithRetryMax(5),
nuget.WithRetryWaitMinMax(time.Second*1, time.Second*10),
)
if err != nil {
panic(fmt.Sprintf("Failed to create client: %v", err))
}
// Get all versions of a package
versions, _, err := client.FindPackageResource.ListAllVersions("MyPackage")
if err != nil {
log.Fatalf("Failed to get package versions: %v", err)
}
// print the versions
for _, v := range versions {
fmt.Printf("Found version %s", v.OriginalVersion)
}
}
For complete usage of go-nuget, see the full package docs.
If you have an issue: report it on the issue tracker
Kevin Berger ([email protected])
Contributions are always welcome. For more information, check out the contributing guide
Licensed under the MIT License. See LICENSE for details.