Documentation
¶
Overview ¶
Simple wrapper around generated EIA API client that embeds a client with a bearer auth interceptor and optional logging middleware
Index ¶
- func GetRoutes(suffixes ...string) []string
- func NewFacets(facets ...*Facet) *eiaapi.Facets
- func ParseResponse(opts *ParseOpts) (reflect.Value, error)
- type Client
- func (client *Client) GetFacet(ctx context.Context, route string, facet string, subs *MethodSubs) (*eiaapi.FacetDetails, error)
- func (client *Client) GetFacets(ctx context.Context, route string, subs *MethodSubs) (*eiaapi.FacetOptionList, error)
- func (client *Client) GetRouteType(ctx context.Context, route string, subs *MethodSubs) (RouteType, error)
- func (client *Client) GetRoutesOrFinalRoute(ctx context.Context, route string, subs *MethodSubs) (*eiaapi.FinalRoute, *eiaapi.Routes, error)
- func (c *Client) Ping() error
- type ClientOpts
- type Facet
- type MethodSubs
- type ParseOpts
- type RouteType
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
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
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 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.