eurostat

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package eurostat is the library behind the eurostat command line: the HTTP client, request shaping, and the typed data models for the Eurostat data API at ec.europa.eu/eurostat.

The Client here is the spine every command shares. It sets a real User-Agent, paces requests so a busy session stays polite, and retries the transient failures (429 and 5xx) that any public API throws under load.

Index

Constants

View Source
const Host = "ec.europa.eu"

Host is the Eurostat dissemination API host.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

Client talks to the Eurostat API over HTTP.

func NewClient

func NewClient(cfg Config) *Client

NewClient returns a Client configured via cfg.

func (*Client) GetData

func (c *Client) GetData(ctx context.Context, dataset string, opts DataOptions) ([]*DataRecord, error)

GetData fetches a dataset and returns flattened records.

func (*Client) GetMetadata

func (c *Client) GetMetadata(ctx context.Context, dataset string) (*Metadata, error)

GetMetadata returns dimension metadata for a dataset.

func (*Client) ListDatasets

func (c *Client) ListDatasets(ctx context.Context, limit int) ([]*DatasetInfo, error)

ListDatasets returns a list of available Eurostat datasets/dataflows.

type Config

type Config struct {
	BaseURL   string
	UserAgent string
	Rate      time.Duration
	Timeout   time.Duration
	Retries   int
}

Config holds all tunables for the Client.

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns sensible defaults.

type DataOptions

type DataOptions struct {
	Geo   string
	Time  string
	Limit int
}

DataOptions holds optional query parameters for GetData.

type DataRecord

type DataRecord struct {
	Dataset   string   `json:"dataset"`
	Geo       string   `json:"geo,omitempty"`
	Time      string   `json:"time,omitempty"`
	Indicator string   `json:"indicator,omitempty"`
	Value     *float64 `json:"value"`
	Unit      string   `json:"unit,omitempty"`
}

DataRecord is one row extracted from a JSON-stat dataset.

type DatasetInfo

type DatasetInfo struct {
	ID      string `json:"id"`
	Name    string `json:"name"`
	Updated string `json:"updated,omitempty"`
}

DatasetInfo describes one Eurostat dataset/dataflow.

type DimensionInfo

type DimensionInfo struct {
	ID     string            `json:"id"`
	Label  string            `json:"label"`
	Values map[string]string `json:"values"` // code -> label
}

DimensionInfo describes one dimension in a dataset.

type Domain

type Domain struct{}

Domain is the eurostat driver. It carries no state; the per-run client is built by the factory Register hands kit.

func (Domain) Classify

func (Domain) Classify(input string) (uriType, id string, err error)

Classify turns a dataset code or Eurostat URL into (type, id).

func (Domain) Info

func (Domain) Info() kit.DomainInfo

Info describes the scheme, the hostnames a pasted link is matched against, and the identity reused for the binary's help and version.

func (Domain) Locate

func (Domain) Locate(uriType, id string) (string, error)

Locate returns the Eurostat databrowser URL for a dataset code.

func (Domain) Register

func (Domain) Register(app *kit.App)

Register installs the client factory and every operation onto app.

type Metadata

type Metadata struct {
	Dataset    string          `json:"dataset"`
	Label      string          `json:"label"`
	Source     string          `json:"source"`
	Updated    string          `json:"updated"`
	Dimensions []DimensionInfo `json:"dimensions"`
}

Metadata describes dimensions of a dataset.

Jump to

Keyboard shortcuts

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