apiclient

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2026 License: GPL-2.0, GPL-2.0-only Imports: 8 Imported by: 0

Documentation

Overview

Package apiclient provides an HTTP client for the SCANOSS REST API.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrUnauthorized indicates the API key is invalid or missing (401).
	ErrUnauthorized = errors.New("unauthorized: invalid API key")

	// ErrForbidden indicates access is denied (403).
	ErrForbidden = errors.New("forbidden: access denied")

	// ErrNotFound indicates the requested resource was not found (404).
	ErrNotFound = errors.New("not found: resource does not exist")

	// ErrServerError indicates a server-side error (500+).
	ErrServerError = errors.New("server error: please try again later")

	// ErrTimeout indicates a request timeout.
	ErrTimeout = errors.New("request timeout")

	// ErrInvalidChecksum indicates the downloaded content checksum doesn't match.
	ErrInvalidChecksum = errors.New("checksum verification failed")
)

Functions

func IsRetryable

func IsRetryable(err error) bool

IsRetryable returns true if the error should be retried.

func IsServerError

func IsServerError(err error) bool

IsServerError returns true if the error is a server error (5xx).

func IsTimeout

func IsTimeout(err error) bool

IsTimeout returns true if the error is a timeout error.

Types

type Client

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

Client is an HTTP client for the SCANOSS REST API.

func NewClient

func NewClient(baseURL, apiKey string) *Client

NewClient creates a new API client.

func NewClientWithHTTPClient added in v0.4.0

func NewClientWithHTTPClient(baseURL, apiKey string, httpClient *http.Client) *Client

NewClientWithHTTPClient creates a new API client with an optional custom HTTP client.

func (*Client) DownloadRuleset

func (c *Client) DownloadRuleset(ctx context.Context, name, version string) ([]byte, *Manifest, error)

DownloadRuleset downloads a ruleset tarball from the API Returns the tarball bytes and the parsed manifest.

type HTTPError

type HTTPError struct {
	StatusCode int
	Message    string
	URL        string
}

HTTPError wraps HTTP-specific errors with status code and message.

func NewHTTPError

func NewHTTPError(statusCode int, message, url string) *HTTPError

NewHTTPError creates a new HTTP error.

func (*HTTPError) Error

func (e *HTTPError) Error() string

type Manifest

type Manifest struct {
	Name           string    `json:"name"`
	Version        string    `json:"version"`
	ChecksumSHA256 string    `json:"checksum_sha256"`
	CreatedAt      time.Time `json:"created_at"`
}

Manifest represents the manifest.json file reconstructed from HTTP headers.

Jump to

Keyboard shortcuts

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