Compare commits

...

4 Commits
v0.1.1 ... main

Author SHA1 Message Date
373581c58a Add docs, improve README
All checks were successful
Build and Publish / release (push) Successful in 1m22s
2024-12-17 17:24:48 -05:00
0bc1b89179 Consolidate actions
All checks were successful
Build and Publish / release (push) Successful in 47s
2024-12-17 16:30:53 -05:00
426f810faf Enable go list
Some checks failed
Build and Publish / build (push) Successful in 1m7s
Build and Publish / publish (push) Failing after 5s
2024-12-17 16:25:31 -05:00
b2506aba90 Upgrade go 2024-12-17 16:15:50 -05:00
23 changed files with 624 additions and 46 deletions

View File

@ -11,7 +11,7 @@ env:
GO_GIT_HOST: gitea.libretechconsulting.com
jobs:
build:
release:
runs-on: ubuntu-latest
steps:
- name: Checkout Code
@ -64,16 +64,12 @@ jobs:
--upload-file ${ZIPFILE} \
"${GITHUB_SERVER_URL}/api/packages/${GITHUB_REPOSITORY_OWNER}/go/upload"
publish:
runs-on: ubuntu-latest
needs: build # Ensure this stage runs only after 'build' is successful
steps:
- name: Run Go List
env:
TAG_NAME: ${{ github.ref_name }} # Use the pushed tag name
run: |
if [[ "$TAG_NAME" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo GOPROXY=proxy.golang.org go list -m libretechconsulting.com/${GITHUB_REPOSITORY}@$TAG_NAME
GOPROXY=proxy.golang.org go list -m gitea.libretechconsulting.com/${GITHUB_REPOSITORY}@$TAG_NAME
else
echo "Error: Invalid tag format '$TAG_NAME'. Expected 'vX.X.X'."
exit 1

View File

@ -10,10 +10,10 @@ GO_FORMATTER := gofumpt
IS_GNU_SED := $(shell sed --version >/dev/null 2>&1 && echo true || echo false)
SED_INLINE := $(if $(filter true,$(IS_GNU_SED)),-i,-i '')
.PHONY: all tools schema generate test build install clean
.PHONY: all tools schema generate test build install docs clean
# Default target
all: tools schema generate test build install
all: tools schema generate test build docs install
tools:
go install golang.org/x/tools/cmd/stringer
@ -56,6 +56,9 @@ build: generate test
install:
go install -v $(CLIENT_PKG)
docs:
bin/eia-client docs md
# Clean up generated files and build artifacts
clean:
rm -rf bin/eia-client

View File

@ -1,3 +1,72 @@
# eia-api-go
A go package for interacting with the EIA API v2
A go package for interacting with the EIA API v2
A client binary for interacting with the EIA API v2
[EIA API Documentation](https://www.eia.gov/opendata/documentation.php)
## 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.
```go
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](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](docs/eia-client.md)
```
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..

View File

@ -1,10 +1,15 @@
# EIA API GO TODO
## Distribution
- [x] Add Gitea CI
- [x] Add Docs
## EIA Package
- [x] Make reflection match a STRING type instead of the underlying type
- [x] Move cmd/eia-client/internal/util/util_reflect to pkg/eia
- [x] Figure out how the fuck to support multiple facets in this piece of shit fucking API spec. Seriously, amateur bullshit.
- [x] Figure out multiple facets, api is challenging with generated code
## EIA Client Tool

View File

@ -0,0 +1,58 @@
package docs
import (
"os"
"gitea.libretechconsulting.com/rmcguire/eia-api-go/cmd/eia-client/internal/util"
"github.com/spf13/cobra"
"github.com/spf13/cobra/doc"
)
var DocsCmd = &cobra.Command{
Use: "docs",
Aliases: []string{"documentation"},
Short: "Generate documentation for eia-client",
Args: cobra.RangeArgs(1, 1),
ValidArgs: []string{"md", "man", "yaml"},
Run: runDocsCmd,
}
func runDocsCmd(cmd *cobra.Command, args []string) {
outDir, err := cmd.Flags().GetString(util.FLAG_OUTPUT_DIR)
if err != nil {
util.Logger(cmd).Fatal().Err(err).Send()
}
prepareDocsDir(cmd, outDir)
switch args[0] {
case "md":
err = doc.GenMarkdownTree(cmd.Root(), outDir)
case "man":
err = doc.GenManTree(cmd.Root(), &doc.GenManHeader{
Title: "EIA Client",
Section: "1",
}, outDir)
case "yaml":
err = doc.GenYamlTree(cmd.Root(), outDir)
default:
util.Logger(cmd).Fatal().Str("docType", args[0]).Msg("invalid doc type given")
}
util.Logger(cmd).Info().Err(err).Msg("doc generation complete")
}
func prepareDocsDir(cmd *cobra.Command, outDir string) {
_, err := os.Stat(outDir)
if err != nil {
err = os.Mkdir(outDir, 0o755)
if err != nil {
util.Logger(cmd).Fatal().Err(err).Str("outdir", outDir).
Msg("unable to prepare output directory")
}
}
}
func init() {
DocsCmd.PersistentFlags().StringP(util.FLAG_OUTPUT_DIR, "o", "./docs", "specify output directory for documentation")
}

View File

@ -31,6 +31,7 @@ import (
"github.com/rs/zerolog"
"github.com/spf13/cobra"
"gitea.libretechconsulting.com/rmcguire/eia-api-go/cmd/eia-client/cmd/docs"
"gitea.libretechconsulting.com/rmcguire/eia-api-go/cmd/eia-client/cmd/get"
"gitea.libretechconsulting.com/rmcguire/eia-api-go/cmd/eia-client/cmd/list"
"gitea.libretechconsulting.com/rmcguire/eia-api-go/cmd/eia-client/internal/util"
@ -98,4 +99,5 @@ func init() {
// Subcommands
rootCmd.AddCommand(list.ListCmd)
rootCmd.AddCommand(get.GetCmd)
rootCmd.AddCommand(docs.DocsCmd)
}

View File

@ -15,6 +15,8 @@ const (
FLAG_LOG_LEVEL = "logLevel"
ENV_LOG_LEVEL = "LOG_LEVEL"
FLAG_OUTPUT_DIR = "outdir"
)
// Type for context data

22
docs/eia-client.md Normal file
View File

@ -0,0 +1,22 @@
## eia-client
Useful utilities for EIA API v2
### Options
```
--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)
```
### SEE ALSO
* [eia-client completion](eia-client_completion.md) - Generate the autocompletion script for the specified shell
* [eia-client docs](eia-client_docs.md) - Generate documentation for eia-client
* [eia-client get](eia-client_get.md) - Commands for getting metadata
* [eia-client list](eia-client_list.md) - Commands for listing metadata
###### Auto generated by spf13/cobra on 17-Dec-2024

View File

@ -0,0 +1,34 @@
## eia-client completion
Generate the autocompletion script for the specified shell
### Synopsis
Generate the autocompletion script for eia-client for the specified shell.
See each sub-command's help for details on how to use the generated script.
### Options
```
-h, --help help for completion
```
### Options inherited from parent commands
```
--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
-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)
```
### SEE ALSO
* [eia-client](eia-client.md) - Useful utilities for EIA API v2
* [eia-client completion bash](eia-client_completion_bash.md) - Generate the autocompletion script for bash
* [eia-client completion fish](eia-client_completion_fish.md) - Generate the autocompletion script for fish
* [eia-client completion powershell](eia-client_completion_powershell.md) - Generate the autocompletion script for powershell
* [eia-client completion zsh](eia-client_completion_zsh.md) - Generate the autocompletion script for zsh
###### Auto generated by spf13/cobra on 17-Dec-2024

View File

@ -0,0 +1,53 @@
## eia-client completion bash
Generate the autocompletion script for bash
### Synopsis
Generate the autocompletion script for the bash shell.
This script depends on the 'bash-completion' package.
If it is not installed already, you can install it via your OS's package manager.
To load completions in your current shell session:
source <(eia-client completion bash)
To load completions for every new session, execute once:
#### Linux:
eia-client completion bash > /etc/bash_completion.d/eia-client
#### macOS:
eia-client completion bash > $(brew --prefix)/etc/bash_completion.d/eia-client
You will need to start a new shell for this setup to take effect.
```
eia-client completion bash
```
### Options
```
-h, --help help for bash
--no-descriptions disable completion descriptions
```
### Options inherited from parent commands
```
--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
-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)
```
### SEE ALSO
* [eia-client completion](eia-client_completion.md) - Generate the autocompletion script for the specified shell
###### Auto generated by spf13/cobra on 17-Dec-2024

View File

@ -0,0 +1,44 @@
## eia-client completion fish
Generate the autocompletion script for fish
### Synopsis
Generate the autocompletion script for the fish shell.
To load completions in your current shell session:
eia-client completion fish | source
To load completions for every new session, execute once:
eia-client completion fish > ~/.config/fish/completions/eia-client.fish
You will need to start a new shell for this setup to take effect.
```
eia-client completion fish [flags]
```
### Options
```
-h, --help help for fish
--no-descriptions disable completion descriptions
```
### Options inherited from parent commands
```
--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
-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)
```
### SEE ALSO
* [eia-client completion](eia-client_completion.md) - Generate the autocompletion script for the specified shell
###### Auto generated by spf13/cobra on 17-Dec-2024

View File

@ -0,0 +1,41 @@
## eia-client completion powershell
Generate the autocompletion script for powershell
### Synopsis
Generate the autocompletion script for powershell.
To load completions in your current shell session:
eia-client completion powershell | Out-String | Invoke-Expression
To load completions for every new session, add the output of the above command
to your powershell profile.
```
eia-client completion powershell [flags]
```
### Options
```
-h, --help help for powershell
--no-descriptions disable completion descriptions
```
### Options inherited from parent commands
```
--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
-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)
```
### SEE ALSO
* [eia-client completion](eia-client_completion.md) - Generate the autocompletion script for the specified shell
###### Auto generated by spf13/cobra on 17-Dec-2024

View File

@ -0,0 +1,55 @@
## eia-client completion zsh
Generate the autocompletion script for zsh
### Synopsis
Generate the autocompletion script for the zsh shell.
If shell completion is not already enabled in your environment you will need
to enable it. You can execute the following once:
echo "autoload -U compinit; compinit" >> ~/.zshrc
To load completions in your current shell session:
source <(eia-client completion zsh)
To load completions for every new session, execute once:
#### Linux:
eia-client completion zsh > "${fpath[1]}/_eia-client"
#### macOS:
eia-client completion zsh > $(brew --prefix)/share/zsh/site-functions/_eia-client
You will need to start a new shell for this setup to take effect.
```
eia-client completion zsh [flags]
```
### Options
```
-h, --help help for zsh
--no-descriptions disable completion descriptions
```
### Options inherited from parent commands
```
--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
-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)
```
### SEE ALSO
* [eia-client completion](eia-client_completion.md) - Generate the autocompletion script for the specified shell
###### Auto generated by spf13/cobra on 17-Dec-2024

29
docs/eia-client_docs.md Normal file
View File

@ -0,0 +1,29 @@
## eia-client docs
Generate documentation for eia-client
```
eia-client docs [flags]
```
### Options
```
-h, --help help for docs
-o, --outdir string specify output directory for documentation (default "./docs")
```
### Options inherited from parent commands
```
--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
-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)
```
### SEE ALSO
* [eia-client](eia-client.md) - Useful utilities for EIA API v2
###### Auto generated by spf13/cobra on 17-Dec-2024

26
docs/eia-client_get.md Normal file
View File

@ -0,0 +1,26 @@
## eia-client get
Commands for getting metadata
### Options
```
-h, --help help for get
```
### Options inherited from parent commands
```
--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
-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)
```
### SEE ALSO
* [eia-client](eia-client.md) - Useful utilities for EIA API v2
* [eia-client get facet](eia-client_get_facet.md) - Describe facet for given API route
* [eia-client get route](eia-client_get_route.md) - Describe a route
###### Auto generated by spf13/cobra on 17-Dec-2024

View File

@ -0,0 +1,28 @@
## eia-client get facet
Describe facet for given API route
```
eia-client get facet route facet [flags]
```
### Options
```
-h, --help help for facet
```
### Options inherited from parent commands
```
--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
-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)
```
### SEE ALSO
* [eia-client get](eia-client_get.md) - Commands for getting metadata
###### Auto generated by spf13/cobra on 17-Dec-2024

View File

@ -0,0 +1,28 @@
## eia-client get route
Describe a route
```
eia-client get route [flags]
```
### Options
```
-h, --help help for route
```
### Options inherited from parent commands
```
--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
-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)
```
### SEE ALSO
* [eia-client get](eia-client_get.md) - Commands for getting metadata
###### Auto generated by spf13/cobra on 17-Dec-2024

26
docs/eia-client_list.md Normal file
View File

@ -0,0 +1,26 @@
## eia-client list
Commands for listing metadata
### Options
```
-h, --help help for list
```
### Options inherited from parent commands
```
--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
-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)
```
### SEE ALSO
* [eia-client](eia-client.md) - Useful utilities for EIA API v2
* [eia-client list facets](eia-client_list_facets.md) - List facets for given API route
* [eia-client list routes](eia-client_list_routes.md) - List routes, optionally by type (default is Data)
###### Auto generated by spf13/cobra on 17-Dec-2024

View File

@ -0,0 +1,28 @@
## eia-client list facets
List facets for given API route
```
eia-client list facets route [flags]
```
### Options
```
-h, --help help for facets
```
### Options inherited from parent commands
```
--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
-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)
```
### SEE ALSO
* [eia-client list](eia-client_list.md) - Commands for listing metadata
###### Auto generated by spf13/cobra on 17-Dec-2024

View File

@ -0,0 +1,31 @@
## eia-client list routes
List routes, optionally by type (default is Data)
```
eia-client list routes [flags]
```
### Options
```
-a, --all List all methods, no filtering
-f, --filters strings Optional [inclusion] filters, case insensitive
-h, --help help for routes
-p, --routePrefix string Prefix for routes, ignore with -a flag (default "Get")
```
### Options inherited from parent commands
```
--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
-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)
```
### SEE ALSO
* [eia-client list](eia-client_list.md) - Commands for listing metadata
###### Auto generated by spf13/cobra on 17-Dec-2024

16
go.mod
View File

@ -1,23 +1,24 @@
module gitea.libretechconsulting.com/rmcguire/eia-api-go
go 1.23.3
go 1.23.4
require (
github.com/deepmap/oapi-codegen v1.16.3
github.com/fatih/color v1.18.0
github.com/goccy/go-yaml v1.15.1
github.com/goccy/go-yaml v1.15.10
github.com/k0kubun/pp/v3 v3.4.1
github.com/oapi-codegen/oapi-codegen/v2 v2.4.1
github.com/oapi-codegen/runtime v1.1.1
github.com/rs/zerolog v1.33.0
github.com/spf13/cobra v1.8.1
golang.org/x/tools v0.27.0
golang.org/x/tools v0.28.0
k8s.io/utils v0.0.0-20241104163129-6fe5fd82f078
mvdan.cc/gofumpt v0.7.0
)
require (
github.com/apapsch/go-jsonmerge/v2 v2.0.0 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.4 // indirect
github.com/dprotaso/go-yit v0.0.0-20240618133044-5a0af90af097 // indirect
github.com/getkin/kin-openapi v0.128.0 // indirect
github.com/go-openapi/jsonpointer v0.21.0 // indirect
@ -27,18 +28,19 @@ require (
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/invopop/yaml v0.3.1 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mailru/easyjson v0.9.0 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 // indirect
github.com/perimeterx/marshmallow v1.1.5 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/speakeasy-api/openapi-overlay v0.9.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/vmware-labs/yaml-jsonpath v0.3.2 // indirect
golang.org/x/mod v0.22.0 // indirect
golang.org/x/sync v0.9.0 // indirect
golang.org/x/sys v0.27.0 // indirect
golang.org/x/text v0.20.0 // indirect
golang.org/x/sync v0.10.0 // indirect
golang.org/x/sys v0.28.0 // indirect
golang.org/x/text v0.21.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

30
go.sum
View File

@ -6,6 +6,7 @@ github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWR
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI=
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU=
github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
github.com/cpuguy83/go-md2man/v2 v2.0.4 h1:wfIWP927BUkWJb2NmU/kNDYIBTh/ziUX91+lVfRxZq4=
github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
@ -31,8 +32,8 @@ github.com/go-quicktest/qt v1.101.0/go.mod h1:14Bz/f7NwaXPtdYEgzsx46kqSxVwTbzVZs
github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0/go.mod h1:fyg7847qk6SyHyPtNmDHnmrv/HOrqktSC+C9fM+CJOE=
github.com/go-test/deep v1.0.8 h1:TDsG77qcSprGbC6vTN8OuXp5g+J+b5Pcguhf7Zt61VM=
github.com/go-test/deep v1.0.8/go.mod h1:5C2ZWiW0ErCdrYzpqxLbTX7MG14M9iiw8DgHncVwcsE=
github.com/goccy/go-yaml v1.15.1 h1:1vwC1ZjDzXyiMUKf7kKPazc6WUm4xnHGxNlzj4BIVu0=
github.com/goccy/go-yaml v1.15.1/go.mod h1:XBurs7gK8ATbW4ZPGKgcbrY1Br56PdM69F7LkFRi1kA=
github.com/goccy/go-yaml v1.15.10 h1:9exV2CDYm/FWHPptIIgcDiPQS+X/4uTR+HEl+GF9xJU=
github.com/goccy/go-yaml v1.15.10/go.mod h1:XBurs7gK8ATbW4ZPGKgcbrY1Br56PdM69F7LkFRi1kA=
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8=
@ -70,8 +71,8 @@ github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0=
github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
github.com/mailru/easyjson v0.9.0 h1:PrnmzHw7262yW8sTBwxi1PdJA3Iw/EKBa8psRf7d9a4=
github.com/mailru/easyjson v0.9.0/go.mod h1:1+xMtQp2MRNVL/V1bOzuP3aP8VNwRW55fQUto+XFtTU=
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
@ -110,6 +111,7 @@ github.com/rogpeppe/go-internal v1.12.0/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99
github.com/rs/xid v1.5.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg=
github.com/rs/zerolog v1.33.0 h1:1cU2KZkvPxNyfgEmhHAz/1A9Bz+llsdYzklWFzgp0r8=
github.com/rs/zerolog v1.33.0/go.mod h1:/7mN4D5sKwJLZQ2b/znpjC3/GQWY/xaDXUM0kKWRHss=
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/sergi/go-diff v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0=
github.com/sergi/go-diff v1.1.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM=
@ -144,13 +146,13 @@ golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7/go.mod h1:qpuaurCH72eLCgpAm/
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
golang.org/x/net v0.0.0-20210428140749-89ef3d95e781/go.mod h1:OJAsFXCWl8Ukc7SiCT/9KSuxbyM7479/AVlXFRxuMCk=
golang.org/x/net v0.0.0-20220225172249-27dd8689420f/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
golang.org/x/net v0.31.0 h1:68CPQngjLL0r2AlUKiSxtQFKvzRVbnzLwMUn5SzcLHo=
golang.org/x/net v0.31.0/go.mod h1:P4fl1q7dY2hnZFxEk4pPSkDHF+QqjitcnDjUQyMM+pM=
golang.org/x/net v0.32.0 h1:ZqPmj8Kzc+Y6e0+skZsuACbx+wzMgo5MQsJh9Qd6aYI=
golang.org/x/net v0.32.0/go.mod h1:CwU0IoeOlnQQWJ6ioyFrfRuomB8GKF6KbYXZVyeXNfs=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.9.0 h1:fEo0HyrW1GIgZdpbhCRO0PkJajUS5H9IFUztCgEo2jQ=
golang.org/x/sync v0.9.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sync v0.10.0 h1:3NQrjDixjgGwUOCaF8w2+VYHv0Ve/vGYSbdkTa98gmQ=
golang.org/x/sync v0.10.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
@ -168,21 +170,21 @@ golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.27.0 h1:wBqf8DvsY9Y/2P8gAfPDEYNuS30J4lPHJxXSb/nJZ+s=
golang.org/x/sys v0.27.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.28.0 h1:Fksou7UEQUWlKvIdsqzJmUmCX3cZuD2+P3XyyzwMhlA=
golang.org/x/sys v0.28.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/text v0.20.0 h1:gK/Kv2otX8gz+wn7Rmb3vT96ZwuoxnQlY+HlJVj7Qug=
golang.org/x/text v0.20.0/go.mod h1:D4IsuqiFMhST5bX19pQ9ikHC2GsaKyk/oF+pn3ducp4=
golang.org/x/text v0.21.0 h1:zyQAAkrwaneQ066sspRyJaG9VNi/YJ1NfzcGB3hZ/qo=
golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20201224043029-2b0845dc783e/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
golang.org/x/tools v0.27.0 h1:qEKojBykQkQ4EynWy4S8Weg69NumxKdn40Fce3uc/8o=
golang.org/x/tools v0.27.0/go.mod h1:sUi0ZgbwW9ZPAq26Ekut+weQPR5eIM6GQLQ1Yjm1H0Q=
golang.org/x/tools v0.28.0 h1:WuB6qZ4RPCQo5aP3WdKZS7i595EdWqWR8vqJTlwTVK8=
golang.org/x/tools v0.28.0/go.mod h1:dcIOrVd3mfQKTgrDVQHqCPMWy6lnhfhtX3hLXYVLfRw=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=

View File

@ -1,3 +1,6 @@
// Simple wrapper around generated EIA API client
// that embeds a client with a bearer auth interceptor
// and optional logging middleware
package eia
import (
@ -21,13 +24,8 @@ const (
defaultLogLevel = zerolog.DebugLevel
)
// Simple wrapper around generated EIA API client
// that embeds a client with a bearer auth interceptor
// and optional logging middleware
//
// Performs a basic availability check against the API
// when creating a new client, and exposes a Ping() method
// for health / readiness probes
// Both marshalled and raw response methods
// loaded into client
type Client struct {
ctx context.Context
apiKey string
@ -36,6 +34,7 @@ type Client struct {
*eiaapi.ClientWithResponses
}
// APIKey is mandatory for interacting with the EIA API
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)
@ -65,6 +64,9 @@ func NewFacets(facets ...*Facet) *eiaapi.Facets {
return &newFacets
}
// 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 NewClient(opts *ClientOpts) (*Client, error) {
baseURL := defaultBaseURL
if opts.BaseURL != nil {
@ -85,14 +87,6 @@ func NewClient(opts *ClientOpts) (*Client, error) {
middlewares := make([]eiaapi.ClientOption, 0, 2)
// Injects Authorization: Bearer <APIKey> header into
// outbound API calls
// basicAuth, err := securityprovider.NewSecurityProviderBearerToken(opts.APIKey)
// if err != nil {
// return nil, err
// }
// middlewares = append(middlewares, eiaapi.WithRequestEditorFn(basicAuth.Intercept))
// Injects API key as query parameter: ?api_key=<apiKey>
paramAuth, err := securityprovider.NewSecurityProviderApiKey("query", "api_key", opts.APIKey)
if err != nil {