Documentation
¶
Overview ¶
Package carbonintensity is the library behind the carbonintensity command line: the HTTP client, request shaping, and the typed data models for the UK Carbon Intensity API (api.carbonintensity.org.uk). No API key required.
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
- type Client
- func (c *Client) GetGeneration(ctx context.Context) ([]GenerationFuel, error)
- func (c *Client) GetHistory(ctx context.Context, from, to string) ([]Intensity, error)
- func (c *Client) GetIntensity(ctx context.Context) (*Intensity, error)
- func (c *Client) GetRegional(ctx context.Context) ([]RegionalIntensity, error)
- type Config
- type Domain
- type GenerationFuel
- type Intensity
- type RegionalIntensity
Constants ¶
const DefaultUserAgent = "carbonintensity-cli/dev (+https://github.com/tamnd/carbonintensity-cli)"
DefaultUserAgent identifies the client to the Carbon Intensity API.
const Host = "api.carbonintensity.org.uk"
Host is the API host this client talks to.
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 Carbon Intensity API over HTTP.
func NewClientWithConfig ¶
NewClientWithConfig returns a Client configured with cfg.
func (*Client) GetGeneration ¶
func (c *Client) GetGeneration(ctx context.Context) ([]GenerationFuel, error)
GetGeneration returns the current generation mix as one record per fuel type.
func (*Client) GetHistory ¶ added in v0.1.1
GetHistory returns carbon intensity records for the given date range. from and to must be ISO 8601 datetime strings, e.g. "2025-01-01T00:00Z".
func (*Client) GetIntensity ¶
GetIntensity returns the current national carbon intensity.
func (*Client) GetRegional ¶
func (c *Client) GetRegional(ctx context.Context) ([]RegionalIntensity, error)
GetRegional returns the current carbon intensity for each of the 18 UK distribution network regions.
type Config ¶
Config holds runtime configuration for the client.
func DefaultConfig ¶
func DefaultConfig() Config
DefaultConfig returns sensible defaults for the Carbon Intensity API.
type Domain ¶
type Domain struct{}
Domain is the carbonintensity driver. It carries no state; the per-run client is built by the factory Register hands kit.
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.
type GenerationFuel ¶
type GenerationFuel struct {
Fuel string `kit:"id" json:"fuel"`
Percent string `json:"percent"` // formatted as "%.1f"
}
GenerationFuel is one fuel's share of the current electricity generation mix.
type Intensity ¶
type Intensity struct {
From string `kit:"id" json:"from"`
To string `json:"to"`
Forecast int `json:"forecast"`
Actual int `json:"actual"`
Index string `json:"index"`
}
Intensity is the current carbon intensity for Great Britain.
type RegionalIntensity ¶
type RegionalIntensity struct {
RegionID int `kit:"id" json:"region_id"`
ShortName string `json:"short_name"`
DNORegion string `json:"dno_region"`
From string `json:"from"`
Forecast int `json:"forecast"`
Index string `json:"index"`
}
RegionalIntensity is the carbon intensity for one UK distribution network region.