Ryan McGuire
373581c58a
All checks were successful
Build and Publish / release (push) Successful in 1m22s
|
||
---|---|---|
.gitea/workflows | ||
api | ||
cmd/eia-client | ||
docs | ||
pkg/eia | ||
schema | ||
.gitignore | ||
go.mod | ||
go.sum | ||
LICENSE | ||
main.go | ||
Makefile | ||
README.md | ||
TODO.md | ||
tools.go |
eia-api-go
A go package for interacting with the EIA API v2
A client binary for interacting with the EIA API v2
EIA Package
The EIA client wrapper at gitea.libretechconsulting.com/rmcguire/eia-api-go/pkg/eia provides a functional set of tools for common EIA API endpoints, and loads in generated endpoints with a client wrapper with auth middleware.
To create a new client, be sure to pass in opts.APIKey.
client, err := eia.NewClient(&eia.ClientOpts{
Context: context.Background(),
APIKey: os.Getenv("EIA_API_KEY"),
LogLevel: os.Getenv("EIA_API_LOG_LEVEL"),
})
if err != nil {
panic(err)
}
Client code is autogenerated from the published swagger spec (see "Download YAML
File" link on EIA website), and a number of corrections have been made. The
swagger spec claims many fields are int, float, etc.. but every single field
I've see has been a quoted string. This and other issues with their spec
required correction, which you can see in the sed
commands in the
Makefile.
EIA Client Binary
A helper tool has been created to make it easier to explore routes and facets, something the API spec alone doesn't help with. It requires at minimum an API key in environment at EIA_API_KEY.
Useful utilities for EIA API v2
Usage:
eia-client [command]
Available Commands:
completion Generate the autocompletion script for the specified shell
get Commands for getting metadata
help Help about any command
list Commands for listing metadata
Flags:
--apiKey string API Key, or set EIA_API_KEY in environment
-L, --apiLogLevel string Log Level for EIA API Middleware, or set EIA_API_LOG_LEVEL in environment
-h, --help help for eia-client
-l, --logLevel string Log Level, or set LOG_LEVEL in environment
-t, --timeout duration Request timeout, or set EIA_API_TMOUT in environment (default 15s)
Use "eia-client [command] --help" for more information about a command.
Installing
go install -v gitea.libretechconsulting.com/rmcguire/eia-api-go/cmd/eia-client@latest
It is strongly suggested to load autocomplete funcs. For zsh, you could add
something like source <(eia-client completion zsh)
to your zshrc/omz, etc..