eia

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2024 License: GPL-3.0, LGPL-3.0 Imports: 13 Imported by: 0

Documentation

Overview

Simple wrapper around generated EIA API client that embeds a client with a bearer auth interceptor and optional logging middleware

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetRoutes

func GetRoutes(suffixes ...string) []string

Return a list of API routes with a given list of function suffixes

func NewFacets

func NewFacets(facets ...*Facet) *eiaapi.Facets

func ParseResponse

func ParseResponse(opts *ParseOpts) (reflect.Value, error)

Types

type Client

type Client struct {
	*eiaapi.Client
	*eiaapi.ClientWithResponses
	// contains filtered or unexported fields
}

Both marshalled and raw response methods loaded into client

func NewClient

func NewClient(opts *ClientOpts) (*Client, error)

Creates a new EIA API client with auth and logging middleware, as well as both marshalled and raw client funcs. Be sure to pass in an API Key in opts.APIKey.

func (*Client) GetFacet

func (client *Client) GetFacet(ctx context.Context, route string, facet string, subs *MethodSubs) (
	*eiaapi.FacetDetails, error,
)

Given an API route and a facet ID, retrieve information about the facet

func (*Client) GetFacets

func (client *Client) GetFacets(ctx context.Context, route string, subs *MethodSubs) (
	*eiaapi.FacetOptionList, error,
)

Return a list of facets given a named route

func (*Client) GetRouteType

func (client *Client) GetRouteType(ctx context.Context, route string, subs *MethodSubs) (RouteType, error)

Checks the route to see if it returns a facet, a list of routes, or a final route

func (*Client) GetRoutesOrFinalRoute

func (client *Client) GetRoutesOrFinalRoute(ctx context.Context, route string, subs *MethodSubs) (
	*eiaapi.FinalRoute, *eiaapi.Routes, error,
)

Retrieve information for a named Route (e.g. GetAeoV2Route1) Returns a *eiaapi.Routes if this is not a final route, otherwise returns a final route response

func (*Client) Ping

func (c *Client) Ping() error

type ClientOpts

type ClientOpts struct {
	Context            context.Context // Base context for requests
	APIKey             string          // API Key [EIA Opendata API v2](https://www.eia.gov/opendata/index.php)
	Logger             *zerolog.Logger // Optional logger, if set is injected into logging middleware
	LogLevel           *zerolog.Level  // Optional log level, default is zerolog.DebugLevel
	BaseURL            *url.URL        // Optional, default is https://api.eia.gov
	HealthCheckTimeout *time.Duration  // Timeout for Ping() function, default is 10s
}

APIKey is mandatory for interacting with the EIA API

type Facet

type Facet struct {
	Name string
	Data interface{}
}

type MethodSubs

type MethodSubs struct {
	TypedParams      map[reflect.Type]reflect.Value // Replace field of specific type with value, must be ptr to type
	StrTypedParams   map[string]reflect.Value       // Parameter types by string name from eiaapi mappings
	StrNamedParams   map[string]reflect.Value       // Parameter names by string name from eiaapi mappings
	RequestEditorFns []eiaapi.RequestEditorFn       // Optional request editor functions
}

For reflected API requests, dynamically replace certain parameters by type

func DefaultMethodSubs

func DefaultMethodSubs(ctx context.Context) *MethodSubs

Prepare default substitutions with a provided context

type ParseOpts

type ParseOpts struct {
	Parser   reflect.Value
	Resp     *http.Response
	JsonOnly bool // Used when parser can correctly unmarshal into type
	BodyOnly bool // Used when API response does not contain openapi spec suggested type
}

If jsonOnly is set, only the parsed value will be returned in a field called JSON200 If there are unmarshaling issues due to code generated from the crappy swagger spec, you may have to manually unmarshal the "Body" field into the correct type. Setting jsonOnly to false will return the entire thing rather than just the JSON200 field.

type RouteType

type RouteType uint8
const (
	RouteTypeRoutes RouteType = iota
	RouteTypeFinal
	RouteTypeFacets
	RouteTypeNotFound
	RouteTypeError
)

func (RouteType) String

func (i RouteType) String() string

Jump to

Keyboard shortcuts

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