v3

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 4, 2025 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package v3 implements the NuGet v3 protocol.

It provides service index discovery, package search, metadata access, and package download functionality for NuGet v3 feeds.

Index

Constants

View Source
const (
	// Search
	ResourceTypeSearchQueryService        = "SearchQueryService"
	ResourceTypeSearchAutocompleteService = "SearchAutocompleteService"

	// Registration (metadata)
	ResourceTypeRegistrationsBaseURL = "RegistrationsBaseUrl"

	// Package download
	ResourceTypePackageBaseAddress = "PackageBaseAddress"

	// Package publish
	ResourceTypePackagePublish = "PackagePublish"

	// Catalog
	ResourceTypeCatalog = "Catalog/3.0.0"
)

Well-known resource types

View Source
const ServiceIndexCacheTTL = 40 * time.Minute

ServiceIndexCacheTTL is the default service index cache TTL (40 minutes as per NuGet spec).

Variables

This section is empty.

Functions

This section is empty.

Types

type AutocompleteClient

type AutocompleteClient struct {
	// contains filtered or unexported fields
}

AutocompleteClient provides package ID and version autocomplete functionality.

func NewAutocompleteClient

func NewAutocompleteClient(httpClient *nugethttp.Client, serviceIndexClient *ServiceIndexClient) *AutocompleteClient

NewAutocompleteClient creates a new autocomplete client.

func (*AutocompleteClient) AutocompletePackageIDs

func (c *AutocompleteClient) AutocompletePackageIDs(ctx context.Context, sourceURL, query string, skip, take int, prerelease bool) (*AutocompleteResponse, error)

AutocompletePackageIDs returns package ID suggestions for a given query.

func (*AutocompleteClient) AutocompletePackageVersions

func (c *AutocompleteClient) AutocompletePackageVersions(ctx context.Context, sourceURL, packageID string, prerelease bool) (*AutocompleteResponse, error)

AutocompletePackageVersions returns version suggestions for a given package ID.

type AutocompleteResponse

type AutocompleteResponse struct {
	TotalHits int      `json:"totalHits"`
	Data      []string `json:"data"`
	Context   any      `json:"@context,omitempty"`
}

AutocompleteResponse represents the response from autocomplete API.

type Dependency

type Dependency struct {
	ID    string `json:"id"`
	Range string `json:"range,omitempty"`
}

Dependency represents a single package dependency.

type DependencyGroup

type DependencyGroup struct {
	TargetFramework string       `json:"targetFramework,omitempty"`
	Dependencies    []Dependency `json:"dependencies,omitempty"`
}

DependencyGroup represents dependencies for a specific target framework.

type DownloadClient

type DownloadClient struct {
	// contains filtered or unexported fields
}

DownloadClient provides package download functionality.

func NewDownloadClient

func NewDownloadClient(httpClient *nugethttp.Client, serviceIndexClient *ServiceIndexClient) *DownloadClient

NewDownloadClient creates a new download client.

func (*DownloadClient) DownloadNuspec

func (c *DownloadClient) DownloadNuspec(ctx context.Context, sourceURL, packageID, version string) (io.ReadCloser, error)

DownloadNuspec downloads the .nuspec manifest file for a package. Caller is responsible for closing the response body.

func (*DownloadClient) DownloadPackage

func (c *DownloadClient) DownloadPackage(ctx context.Context, sourceURL, packageID, version string) (io.ReadCloser, error)

DownloadPackage downloads a .nupkg file and returns the response body. Caller is responsible for closing the response body.

func (*DownloadClient) GetPackageVersions

func (c *DownloadClient) GetPackageVersions(ctx context.Context, sourceURL, packageID string) ([]string, error)

GetPackageVersions lists all available versions for a package. Uses the package base address versions endpoint.

type MetadataClient

type MetadataClient struct {
	// contains filtered or unexported fields
}

MetadataClient provides package metadata functionality.

func NewMetadataClient

func NewMetadataClient(httpClient *nugethttp.Client, serviceIndexClient *ServiceIndexClient) *MetadataClient

NewMetadataClient creates a new metadata client.

func (*MetadataClient) GetPackageMetadata

func (c *MetadataClient) GetPackageMetadata(ctx context.Context, sourceURL, packageID string) (*RegistrationIndex, error)

GetPackageMetadata retrieves metadata for a specific package ID. Returns all versions and their metadata.

func (*MetadataClient) GetVersionMetadata

func (c *MetadataClient) GetVersionMetadata(ctx context.Context, sourceURL, packageID, version string) (*RegistrationCatalog, error)

GetVersionMetadata retrieves metadata for a specific package version.

func (*MetadataClient) ListVersions

func (c *MetadataClient) ListVersions(ctx context.Context, sourceURL, packageID string) ([]string, error)

ListVersions returns all available versions for a package.

func (*MetadataClient) SetHTTPCache

func (c *MetadataClient) SetHTTPCache(httpCache *cache.DiskCache)

SetHTTPCache configures the HTTP disk cache for registration API responses. Cache key format matches NuGet.Client: list_{packageid}_index, list_{packageid}_range_{lower}-{upper}

type PackageType

type PackageType struct {
	Name    string `json:"name"`
	Version string `json:"version,omitempty"`
}

PackageType represents the type of package.

type RegistrationCatalog

type RegistrationCatalog struct {
	ID                       string            `json:"@id"`
	PackageID                string            `json:"id"`
	Version                  string            `json:"version"`
	Authors                  string            `json:"authors,omitempty"`
	Description              string            `json:"description,omitempty"`
	IconURL                  string            `json:"iconUrl,omitempty"`
	LicenseURL               string            `json:"licenseUrl,omitempty"`
	LicenseExpression        string            `json:"licenseExpression,omitempty"`
	ProjectURL               string            `json:"projectUrl,omitempty"`
	Published                string            `json:"published,omitempty"`
	RequireLicenseAcceptance bool              `json:"requireLicenseAcceptance"`
	Summary                  string            `json:"summary,omitempty"`
	Tags                     []string          `json:"tags,omitempty"`
	Title                    string            `json:"title,omitempty"`
	DependencyGroups         []DependencyGroup `json:"dependencyGroups,omitempty"`
	PackageTypes             []PackageType     `json:"packageTypes,omitempty"`
}

RegistrationCatalog contains detailed package metadata.

type RegistrationIndex

type RegistrationIndex struct {
	Count int                `json:"count"`
	Items []RegistrationPage `json:"items"`
}

RegistrationIndex represents the top-level registration index.

type RegistrationLeaf

type RegistrationLeaf struct {
	ID             string               `json:"@id"`
	CatalogEntry   *RegistrationCatalog `json:"catalogEntry"`
	PackageContent string               `json:"packageContent"`
}

RegistrationLeaf represents a single package version registration.

type RegistrationPage

type RegistrationPage struct {
	ID    string             `json:"@id"`
	Count int                `json:"count"`
	Items []RegistrationLeaf `json:"items,omitempty"`
	Lower string             `json:"lower"`
	Upper string             `json:"upper"`
}

RegistrationPage represents a page of registration entries.

type Resource

type Resource struct {
	ID      string `json:"@id"`
	Type    string `json:"@type"`
	Comment string `json:"comment,omitempty"`
}

Resource represents a service resource in the service index.

type SearchClient

type SearchClient struct {
	// contains filtered or unexported fields
}

SearchClient provides package search functionality.

func NewSearchClient

func NewSearchClient(httpClient *nugethttp.Client, serviceIndexClient *ServiceIndexClient) *SearchClient

NewSearchClient creates a new search client.

func (*SearchClient) Search

func (c *SearchClient) Search(ctx context.Context, sourceURL string, opts SearchOptions) (*SearchResponse, error)

Search searches for packages matching the query.

func (*SearchClient) SearchSimple

func (c *SearchClient) SearchSimple(ctx context.Context, sourceURL, query string) (*SearchResponse, error)

SearchSimple performs a simple search with default options.

type SearchOptions

type SearchOptions struct {
	Query       string
	Skip        int
	Take        int
	Prerelease  bool
	SemVerLevel string // "2.0.0" for SemVer 2.0 support
}

SearchOptions holds search parameters.

type SearchResponse

type SearchResponse struct {
	TotalHits int            `json:"totalHits"`
	Data      []SearchResult `json:"data"`
	Context   any            `json:"@context,omitempty"`
}

SearchResponse represents the response from the search API.

type SearchResult

type SearchResult struct {
	ID             string          `json:"@id"`
	Type           string          `json:"@type"`
	Registration   string          `json:"registration,omitempty"`
	PackageID      string          `json:"id"`
	Version        string          `json:"version"`
	Description    string          `json:"description"`
	Summary        string          `json:"summary,omitempty"`
	Title          string          `json:"title,omitempty"`
	IconURL        string          `json:"iconUrl,omitempty"`
	LicenseURL     string          `json:"licenseUrl,omitempty"`
	ProjectURL     string          `json:"projectUrl,omitempty"`
	Tags           []string        `json:"tags,omitempty"`
	Authors        []string        `json:"authors,omitempty"`
	TotalDownloads int64           `json:"totalDownloads"`
	Verified       bool            `json:"verified"`
	Versions       []SearchVersion `json:"versions,omitempty"`
}

SearchResult represents a single search result.

type SearchVersion

type SearchVersion struct {
	Version   string `json:"version"`
	Downloads int64  `json:"downloads"`
	ID        string `json:"@id"`
}

SearchVersion represents a version in search results.

type ServiceIndex

type ServiceIndex struct {
	Version   string     `json:"version"`
	Resources []Resource `json:"resources"`
	Context   any        `json:"@context,omitempty"`
}

ServiceIndex represents the NuGet v3 service index. See: https://docs.microsoft.com/en-us/nuget/api/service-index

type ServiceIndexClient

type ServiceIndexClient struct {
	// contains filtered or unexported fields
}

ServiceIndexClient provides access to NuGet v3 service index.

func NewServiceIndexClient

func NewServiceIndexClient(httpClient *nugethttp.Client) *ServiceIndexClient

NewServiceIndexClient creates a new service index client.

func NewServiceIndexClientWithCache

func NewServiceIndexClientWithCache(httpClient *nugethttp.Client, mtCache *cache.MultiTierCache) *ServiceIndexClient

NewServiceIndexClientWithCache creates a new service index client with optional disk cache.

func (*ServiceIndexClient) ClearCache

func (c *ServiceIndexClient) ClearCache()

ClearCache removes all cached service indexes.

func (*ServiceIndexClient) GetAllResourceURLs

func (c *ServiceIndexClient) GetAllResourceURLs(ctx context.Context, sourceURL, resourceType string) ([]string, error)

GetAllResourceURLs finds all resources of the given type. Matches resource types with or without version suffixes (e.g., "PackageBaseAddress" matches "PackageBaseAddress/3.0.0").

func (*ServiceIndexClient) GetResourceURL

func (c *ServiceIndexClient) GetResourceURL(ctx context.Context, sourceURL, resourceType string) (string, error)

GetResourceURL finds the first resource of the given type. Matches resource types with or without version suffixes (e.g., "PackageBaseAddress" matches "PackageBaseAddress/3.0.0").

func (*ServiceIndexClient) GetServiceIndex

func (c *ServiceIndexClient) GetServiceIndex(ctx context.Context, sourceURL string) (*ServiceIndex, error)

GetServiceIndex retrieves the service index for a given source URL. Caches the result for ServiceIndexCacheTTL.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL