api

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2026 License: MIT Imports: 17 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package api is a thin, secret-safe client for the Seznam Webmaster REST API.

The API authenticates with a `key` query parameter, so the key is part of every request URL. This package therefore never lets a URL escape: transport errors are stripped of it, trace output is redacted, redirects are not followed and the base URL is restricted to the official host or loopback.

Index

Constants

View Source
const AllowAnyBaseURLEnv = "SZWM_INSECURE_ALLOW_ANY_BASE_URL"

AllowAnyBaseURLEnv opts out of the base URL host restriction.

View Source
const DefaultBaseURL = "https://reporter.seznam.cz/wm-api"

DefaultBaseURL is the production endpoint. The swagger.json `basePath` (/wm-api/wm-api) is wrong: the working prefix is a single /wm-api.

View Source
const KeyURL = "https://reporter.seznam.cz/wm/web/api-klic"

KeyURL is where a user finds the API key of the selected site.

Variables

This section is empty.

Functions

func Decode

func Decode(body []byte) (any, error)

Decode parses a JSON body keeping integers exact and unknown fields intact. szwm passes unknown fields through because the API already returns more than its schema documents.

func Int

func Int(v any) (int64, bool)

Int reads an integer from a decoded JSON value.

func MissingKeyError

func MissingKeyError() *apperr.Error

MissingKeyError is the error for a call that needs a key but has none.

func Redact

func Redact(s, key string) string

Redact removes key, raw or URL-encoded, and any key= parameter from s.

func ValidateBaseURL

func ValidateBaseURL(raw string) error

ValidateBaseURL allows only the official host or loopback. An agent tricked into passing another host would otherwise hand the API key to that host.

func ValidatePath

func ValidatePath(p string) error

ValidatePath keeps a caller-supplied path on the API host.

Types

type Client

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

Client talks to the Webmaster API.

func New

func New(opts Options) (*Client, error)

New validates options and returns a Client.

func (*Client) BaseURL

func (c *Client) BaseURL() string

BaseURL returns the effective base URL.

func (*Client) Do

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

Do performs a request with rate limiting and retries.

func (*Client) HasKey

func (c *Client) HasKey() bool

HasKey reports whether an API key is configured.

func (*Client) Redact

func (c *Client) Redact(s string) string

Redact removes the API key from a string.

func (*Client) Stats

func (c *Client) Stats() Stats

Stats returns cumulative counters.

type Limiter

type Limiter interface {
	Wait(ctx context.Context) error
}

Limiter delays a request until it fits into the published rate limits.

type Options

type Options struct {
	BaseURL    string
	Key        string
	Timeout    time.Duration
	Retries    int
	UserAgent  string
	Limiter    Limiter
	Trace      io.Writer
	HTTPClient *http.Client
	// Sleep is replaceable so tests do not wait for real backoff.
	Sleep func(ctx context.Context, d time.Duration) error
}

Options configure a Client.

type Request

type Request struct {
	Method string
	Path   string
	Query  url.Values
	NoAuth bool
}

Request describes one API call. The API key is added automatically unless NoAuth is set.

type Response

type Response struct {
	Status int
	Body   []byte
}

Response is a successful (2xx with body) API response.

type Stats

type Stats struct {
	Requests int64 `json:"requests"`
	Retries  int64 `json:"retries"`
}

Stats counts HTTP activity for result metadata.

Jump to

Keyboard shortcuts

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