Skip to content

huhouhua/go-nuget

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
go-nuget

easy golang nuget client module

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!

InstallationCoverageUsageExamplesLicense

Workflow ci GitHub license release GoDoc GitHub go.mod Go version Go Report Card Test Coverage

🤘  Coverage

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

🚀  Installation and Documentation

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.

📄  Usage

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))
}

🥙  Examples

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.

Full Examples

Full Examples : API Resources Operations

Full Examples : Package Find Operations

Full Examples : Package Read and Create Operations

Full Examples : Package Search Operations

Full Examples : Package Metadata Operations

Full Examples : Package Push Operations

🤝 Issues

If you have an issue: report it on the issue tracker

👤 Author

Kevin Berger ([email protected])

🧑‍💻 Contributing

Contributions are always welcome. For more information, check out the contributing guide

📘  License

Licensed under the MIT License. See LICENSE for details.

Packages

No packages published

Contributors 2

  •  
  •  

Languages