Add docs, improve README
All checks were successful
Build and Publish / release (push) Successful in 1m22s

This commit is contained in:
2024-12-17 17:24:48 -05:00
parent 0bc1b89179
commit 373581c58a
22 changed files with 601 additions and 19 deletions

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 {