Documentation
¶
Overview ¶
Package emissions implements clients to fetch emission factors from different sources
Index ¶
- Variables
- func ISO23Map() map[string]string
- func ISO32Map() map[string]string
- func Register(provider string, providerName string, ...)
- type Client
- type ContextKey
- type ContextValues
- type CountryCode
- type CountryCodeFields
- type EmissionFactor
- type EmissionFactors
- type FactorProviders
- type PayLoad
- type Provider
- func NewEMapsProvider(logger *slog.Logger) (Provider, error)
- func NewGlobalProvider(logger *slog.Logger) (Provider, error)
- func NewOWIDProvider(logger *slog.Logger) (Provider, error)
- func NewRTEProvider(logger *slog.Logger) (Provider, error)
- func NewWattTimeProvider(logger *slog.Logger) (Provider, error)
Constants ¶
This section is empty.
Variables ¶
var ( ErrMissingAPIToken = errors.New("api token missing for Electricity Maps") ErrMissingInput = errors.New("missing username/password/region for Watt Time") ErrMissingData = errors.New("missing data in Watt Time response") ErrNoValidProviders = errors.New("no valid emission data providers found") )
Custom errors.
Functions ¶
Types ¶
type ContextValues ¶
ContextValues contains the values to be set in context.
type CountryCode ¶
type CountryCode struct {
IsoCode []CountryCodeFields `json:"3166-1"`
}
CountryCode contains data of countries ISO codes.
var CountryCodes CountryCode
type CountryCodeFields ¶
type CountryCodeFields struct {
Alpha2Code string `json:"alpha_2"`
Alpha3Code string `json:"alpha_3"`
Name string `json:"name"`
NumericalCode string `json:"numeric"`
}
CountryCodeFields contains different ISO codes of a given country.
type EmissionFactor ¶
EmissionFactor is the container for emission factor value. The name can be country name or zone name based on the provider used.
type EmissionFactors ¶
type EmissionFactors map[string]EmissionFactor
EmissionFactors returns a map of country code in ISO-2 with latest emission factor.
type FactorProviders ¶
type FactorProviders struct {
Providers map[string]Provider
ProviderNames map[string]string
// contains filtered or unexported fields
}
FactorProviders implements the interface to collect emission factors from different sources.
func NewFactorProviders ¶
func NewFactorProviders(logger *slog.Logger, enabled []string) (*FactorProviders, error)
NewFactorProviders creates a new EmissionProviders.
func (FactorProviders) Collect ¶
func (e FactorProviders) Collect() map[string]PayLoad
Collect implements collection of emission factors from different providers.
func (FactorProviders) Stop ¶
func (e FactorProviders) Stop() error
Stop terminates tickers (when present) from different providers.
type PayLoad ¶
type PayLoad struct {
Factor EmissionFactors
Name string
}
PayLoad contains emissions factor.
type Provider ¶
type Provider interface {
// Update current emission factor
Update() (EmissionFactors, error)
// Stop updaters and release resources
Stop() error
}
Provider is the interface a emission provider has to implement.
func NewEMapsProvider ¶
NewEMapsProvider returns a new Provider that returns emission factor from electricity maps data.
func NewGlobalProvider ¶
NewGlobalProvider returns a new Provider that returns a constant global average emission factor.
func NewOWIDProvider ¶
NewOWIDProvider returns a new Provider that returns emission factor from OWID data.
func NewRTEProvider ¶
NewRTEProvider returns a new Provider that returns emission factor from RTE eCO2 mix.