client

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// BaseURL is the Ahrefs API v3 base URL
	BaseURL = "https://api.ahrefs.com/v3"

	// DefaultTimeout for HTTP requests
	DefaultTimeout = 60 * time.Second

	// DefaultMaxRetries for failed requests
	DefaultMaxRetries = 3
)

Variables

This section is empty.

Functions

This section is empty.

Types

type APIError

type APIError struct {
	StatusCode int
	Code       string
	Message    string
	Suggestion string
	DocsURL    string
}

APIError represents an error response from the API

func (*APIError) Error

func (e *APIError) Error() string

type Client

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

Client is the Ahrefs API client

func NewClient

func NewClient(cfg Config) *Client

NewClient creates a new Ahrefs API client

func (*Client) Do

func (c *Client) Do(ctx context.Context, req Request) (*Response, error)

Do executes an API request

func (*Client) Get

func (c *Client) Get(ctx context.Context, endpoint string, params url.Values) (*Response, error)

Get performs a GET request

func (*Client) Post

func (c *Client) Post(ctx context.Context, endpoint string, params url.Values) (*Response, error)

Post performs a POST request

type Config

type Config struct {
	APIKey     string
	BaseURL    string
	Timeout    time.Duration
	MaxRetries int
}

Config holds client configuration

type Request

type Request struct {
	Method   string
	Endpoint string
	Params   url.Values
}

Request represents an API request

type Response

type Response struct {
	StatusCode int
	Body       []byte
	Headers    http.Header
	Meta       ResponseMeta
}

Response represents an API response with metadata

type ResponseMeta

type ResponseMeta struct {
	UnitsConsumed      int   `json:"units_consumed,omitempty"`
	RateLimitRemaining int   `json:"rate_limit_remaining,omitempty"`
	ResponseTimeMS     int64 `json:"response_time_ms"`
}

ResponseMeta contains metadata about the API response

Jump to

Keyboard shortcuts

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