32 lines
785 B
Go
32 lines
785 B
Go
// Package collect owns upstream weather source collection for application use.
|
|
package collect
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"gitea.maximumdirect.net/eric/weatherreporter/internal/adapters/weatherapi"
|
|
"gitea.maximumdirect.net/eric/weatherreporter/internal/config"
|
|
"gitea.maximumdirect.net/eric/weatherreporter/internal/weatherdata"
|
|
)
|
|
|
|
type Request struct {
|
|
Config config.Config
|
|
}
|
|
|
|
type Result struct {
|
|
Bundle *weatherdata.Bundle
|
|
}
|
|
|
|
func Run(ctx context.Context, req Request) (*Result, error) {
|
|
client, err := weatherapi.New(req.Config)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("prepare weather collection: %w", err)
|
|
}
|
|
bundle, err := client.FetchBundle(ctx)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("collect weather bundle: %w", err)
|
|
}
|
|
return &Result{Bundle: bundle}, nil
|
|
}
|