Documentation ¶
Overview ¶
Package api provides functionality for interacting with the EdgeCom Energy API.
The package implements:
- Robust HTTP client with timeouts and context support
- Automatic data conversion and storage
- Historical data bootstrapping
- Structured logging
- Error handling with custom error types
Example:
fetcher := api.NewSeriesFetcher( "https://api.example.com/timeseries", dbService, logger, ) if err := fetcher.FetchData(ctx, start, end); err != nil { log.Printf("Failed to fetch data: %v", err) return err }
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // ErrAPIRequest is returned when there's an error making an API request ErrAPIRequest = errors.New("error making API request") // ErrAPIStatus is returned when the API returns a non-200 status code ErrAPIStatus = errors.New("error status from API") )
Error types for API-related errors
Functions ¶
This section is empty.
Types ¶
type SeriesFetcher ¶
type SeriesFetcher struct {
// contains filtered or unexported fields
}
SeriesFetcher is a struct that fetches data from the EdgeCom Energy API and stores it in a database.
func NewSeriesFetcher ¶
func NewSeriesFetcher(apiURL string, dbService database.TimeSeriesRepository, logger *logrus.Logger) *SeriesFetcher
NewSeriesFetcher creates a new SeriesFetcher instance. Parameters:
- apiURL: The base URL for the EdgeCom API
- dbService: Repository for storing time series data
- logger: Structured logger for operation tracking
Returns:
- A configured SeriesFetcher instance ready for use
func (*SeriesFetcher) BootstrapHistoricalData ¶
func (f *SeriesFetcher) BootstrapHistoricalData(ctx context.Context) error
BootstrapHistoricalData initializes the database with historical data. It attempts to fetch the last 2 years of data, with a fallback to the last 24 hours if the full historical fetch fails.
The method implements a graceful degradation strategy:
- Attempts to fetch 2 years of historical data
- On failure, falls back to last 24 hours
- Logs all operations and failures
Click to show internal directories.
Click to hide internal directories.