add simple fetch to another service

This commit is contained in:
2025-10-30 14:44:26 +01:00
parent e0929aff56
commit 802dfc97a2
2 changed files with 37 additions and 4 deletions
+27 -2
View File
@@ -2,12 +2,17 @@ package meteo
import (
"context"
"fmt"
"log/slog"
"net/http"
"sync"
"time"
)
type inMemory struct {
data map[string]MeteoData
mu *sync.RWMutex
data any
mu *sync.RWMutex
expiry time.Time
}
type Service struct {
inMemory
@@ -18,5 +23,25 @@ func NewService() *Service {
}
func (s *Service) GetWeatherByCity(ctx context.Context, params GetMeteoData) ([]MeteoData, error) {
fromDate, err := time.Parse("2006-01-02", params.Date)
if err != nil {
return nil, err
}
toDate := fromDate.AddDate(0, 0, params.Days-1)
url := fmt.Sprintf("http://localhost:8080/data?city=%s&from=%s&to=%s",
params.Location, params.Date, toDate.Format("2006-01-02"))
resp, err := http.Get(url)
if err != nil {
return nil, err
}
defer resp.Body.Close()
// TODO add backoff
// TODO add ristretto
slog.Info("fetched data", "data", resp)
return []MeteoData{}, nil
}