-
Notifications
You must be signed in to change notification settings - Fork 8
/
front.go
62 lines (55 loc) 路 1.78 KB
/
front.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package front
import (
"context"
"fmt"
"goa.design/clue/example/weather/services/front/clients/forecaster"
"goa.design/clue/example/weather/services/front/clients/locator"
"goa.design/clue/example/weather/services/front/clients/tester"
genfront "goa.design/clue/example/weather/services/front/gen/front"
)
type (
// Service is the front service implementation.
Service struct {
fc forecaster.Client
lc locator.Client
tc tester.Client
}
)
// New instantiates a new front service.
func New(fc forecaster.Client, lc locator.Client, tc tester.Client) *Service {
return &Service{fc: fc, lc: lc, tc: tc}
}
// Forecast returns the forecast for the location at the given IP.
func (s *Service) Forecast(ctx context.Context, ip string) (*genfront.Forecast2, error) {
l, err := s.lc.GetLocation(ctx, ip)
if err != nil {
return nil, err
}
if l.Country != "United States" {
return nil, genfront.MakeNotUsa(fmt.Errorf("IP not in the US (%s)", l.Country))
}
f, err := s.fc.GetForecast(ctx, l.Lat, l.Long)
if err != nil {
return nil, err
}
loc := genfront.Location{
Lat: l.Lat,
Long: l.Long,
City: l.City,
State: l.Region,
}
ps := make([]*genfront.Period, len(f.Periods))
for i, p := range f.Periods {
pval := genfront.Period(*p)
ps[i] = &pval
}
return &genfront.Forecast2{Location: &loc, Periods: ps}, nil
}
// Runs ALL API Integration Tests from the Tester service, allowing for filtering on included or excluded tests
func (s *Service) TestAll(ctx context.Context, payload *genfront.TestAllPayload) (*genfront.TestResults, error) {
return s.tc.TestAll(ctx, payload.Include, payload.Exclude)
}
// Runs API Integration Tests' Smoke Tests ONLY from the Tester service
func (s *Service) TestSmoke(ctx context.Context) (*genfront.TestResults, error) {
return s.tc.TestSmoke(ctx)
}