A go package for interacting with the EIA API v2
Go to file
Ryan McGuire 373581c58a
All checks were successful
Build and Publish / release (push) Successful in 1m22s
Add docs, improve README
2024-12-17 17:24:48 -05:00
.gitea/workflows Consolidate actions 2024-12-17 16:30:53 -05:00
api Support non-final routes 2024-11-29 16:58:12 -05:00
cmd/eia-client Add docs, improve README 2024-12-17 17:24:48 -05:00
docs Add docs, improve README 2024-12-17 17:24:48 -05:00
pkg/eia Add docs, improve README 2024-12-17 17:24:48 -05:00
schema Support non-final routes 2024-11-29 16:58:12 -05:00
.gitignore exclude vscode 2024-11-19 08:42:42 -05:00
go.mod Add docs, improve README 2024-12-17 17:24:48 -05:00
go.sum Add docs, improve README 2024-12-17 17:24:48 -05:00
LICENSE Move to public repo 2024-12-17 16:02:58 -05:00
main.go Start adding tests 2024-12-05 12:36:49 -05:00
Makefile Add docs, improve README 2024-12-17 17:24:48 -05:00
README.md Add docs, improve README 2024-12-17 17:24:48 -05:00
TODO.md Add docs, improve README 2024-12-17 17:24:48 -05:00
tools.go Add gofumpt to tools 2024-12-16 14:24:31 -05:00

eia-api-go

A go package for interacting with the EIA API v2

A client binary for interacting with the EIA API v2

EIA API Documentation

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.

EIA Client Documentation

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..