Documentation
¶
Overview ¶
Package client provides a comprehensive API client for Snyk with rate limiting, retry logic, and integration with go-application-framework.
Package client provides API versioning support for Snyk REST API.
Index ¶
- Variables
- func IsAuthError(err error) bool
- func IsNotFound(err error) bool
- func IsRetryable(err error) bool
- type APIError
- type APIVersion
- type Client
- func (c *Client) APIVersion() APIVersion
- func (c *Client) BaseURL() string
- func (c *Client) Close() error
- func (c *Client) Execute(ctx context.Context, req *http.Request) (*http.Response, error)
- func (c *Client) GetConfiguration() configuration.Configuration
- func (c *Client) GetLogger() *zerolog.Logger
- func (c *Client) GetNetworkAccess() networking.NetworkAccess
- func (c *Client) HTTPClient() *http.Client
- func (c *Client) RestBaseURL() string
- func (c *Client) Token() string
- type Option
- func WithBaseURL(v1URL, restURL string) Option
- func WithEngine(engine workflow.Engine) Option
- func WithLogger(logger *zerolog.Logger) Option
- func WithRateLimit(burstSize int, period time.Duration) Option
- func WithRetryPolicy(maxRetries int, baseDelay, maxDelay time.Duration) Option
- func WithUserAgent(ua string) Option
- func WithVersion(version APIVersion) Option
Constants ¶
This section is empty.
Variables ¶
var ( ErrAuthentication = errors.New("authentication failed") ErrNotFound = errors.New("resource not found") ErrRateLimited = errors.New("rate limited by server") ErrServerError = errors.New("server error") ErrTimeout = errors.New("request timeout") ErrMaxRetries = errors.New("maximum retries exceeded") )
Sentinel errors for common API error conditions.
var ErrInvalidVersion = &APIError{
Message: "invalid API version format (expected YYYY-MM-DD or YYYY-MM-DD~stability)",
}
ErrInvalidVersion is returned when an API version string is invalid.
Functions ¶
func IsAuthError ¶
IsAuthError returns true if the error is an authentication error.
func IsNotFound ¶
IsNotFound returns true if the error is a 404 Not Found.
func IsRetryable ¶
IsRetryable returns true if the error can be retried.
Types ¶
type APIError ¶
type APIError struct {
StatusCode int
Message string
RequestID string
SnykRequestID string
Retryable bool
RetryAfter time.Duration
Cause error
}
APIError provides detailed error information from API responses.
func NewAPIError ¶
NewAPIError creates a new APIError from an HTTP response.
type APIVersion ¶
type APIVersion string
APIVersion represents a Snyk REST API version.
const ( Version20251105 APIVersion = "2025-11-05" // Latest GA (current spec) Version20240422 APIVersion = "2024-04-22" // go-application-framework default Version20231127 APIVersion = "2023-11-27" // Common stable version )
Common stable API versions.
const DefaultAPIVersion APIVersion = "2025-11-05"
DefaultAPIVersion is the latest stable GA version used by default.
func ParseVersion ¶
func ParseVersion(s string) (APIVersion, error)
ParseVersion parses a string into an APIVersion, validating the format. Returns an error if the format is invalid.
func (APIVersion) Beta ¶
func (v APIVersion) Beta() APIVersion
Beta returns the beta version of this API version.
func (APIVersion) Experimental ¶
func (v APIVersion) Experimental() APIVersion
Experimental returns the experimental version of this API version.
func (APIVersion) String ¶
func (v APIVersion) String() string
String returns the string representation of the API version.
func (APIVersion) WithStability ¶
func (v APIVersion) WithStability(stability string) APIVersion
WithStability adds a stability suffix to the version.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is the main API client that handles authentication, rate limiting, and request execution using go-application-framework.
func (*Client) APIVersion ¶
func (c *Client) APIVersion() APIVersion
APIVersion returns the configured API version.
func (*Client) GetConfiguration ¶
func (c *Client) GetConfiguration() configuration.Configuration
GetConfiguration returns the framework configuration.
func (*Client) GetNetworkAccess ¶
func (c *Client) GetNetworkAccess() networking.NetworkAccess
GetNetworkAccess returns the underlying network access for direct requests.
func (*Client) HTTPClient ¶
HTTPClient returns the underlying HTTP client for direct requests.
func (*Client) RestBaseURL ¶
RestBaseURL returns the REST API base URL.
type Option ¶
type Option func(*config)
Option is a functional option for configuring the Client.
func WithBaseURL ¶
WithBaseURL sets custom API base URLs. This is useful for regional endpoints or testing.
func WithEngine ¶
WithEngine sets the workflow engine to use. If not provided, a standalone engine will be created.
func WithLogger ¶
WithLogger sets the logger for the client.
func WithRateLimit ¶
WithRateLimit sets rate limiting configuration.
func WithRetryPolicy ¶
WithRetryPolicy sets retry configuration.
func WithUserAgent ¶
WithUserAgent sets a custom user agent prefix.
func WithVersion ¶
func WithVersion(version APIVersion) Option
WithVersion sets a specific API version for requests. If not specified, DefaultAPIVersion is used.
Example:
client.WithVersion(client.Version20240422)
client.WithVersion(client.DefaultAPIVersion.Beta())
client.WithVersion("2024-01-01")