-
Notifications
You must be signed in to change notification settings - Fork 3
Open
Labels
Description
Summary
Combine Multiple Sources
// NEW: internal/mcp/handlers.go
type EnrichedParkInfo struct {
Park models.Park `json:"park"`
Alerts []models.Alert `json:"alerts,omitempty"`
Weather *models.Weather `json:"current_weather,omitempty"`
Nearby []models.RecreationArea `json:"nearby_recreation,omitempty"`
}
func (s *Server) handleGetCompleteParkInfo(ctx context.Context, input GetParkDetailsInput) (*EnrichedParkInfo, error) {
// Parallel fetching with errgroup
var (
park *models.Park
alerts []models.Alert
weather *models.Weather
)
g, gctx := errgroup.WithContext(ctx)
g.Go(func() error {
var err error
park, err = s.npsClient.GetParkDetails(gctx, input.ParkCode)
return err
})
g.Go(func() error {
var err error
alerts, err = s.npsClient.GetAlerts(gctx, input.ParkCode)
return err
})
g.Go(func() error {
if park != nil && park.Latitude != "" {
lat, _ := strconv.ParseFloat(park.Latitude, 64)
lon, _ := strconv.ParseFloat(park.Longitude, 64)
var err error
weather, err = s.weatherClient.GetCurrentWeather(gctx, lat, lon, "imperial")
return err
}
return nil
})
if err := g.Wait(); err != nil {
return nil, err
}
return &EnrichedParkInfo{
Park: *park,
Alerts: alerts,
Weather: weather,
}, nil
}Reactions are currently unavailable