Add canonical weather collection package
This commit is contained in:
31
internal/collect/collect.go
Normal file
31
internal/collect/collect.go
Normal file
@@ -0,0 +1,31 @@
|
||||
// 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
|
||||
}
|
||||
Reference in New Issue
Block a user