-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcli_map.go
40 lines (32 loc) · 810 Bytes
/
cli_map.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
package main
import (
"errors"
"fmt"
)
func commandMapf(cfg *config, args ...string) error {
locationsResp, err := cfg.pokeapiClient.ListLocations(cfg.nextLocationsURL)
if err != nil {
return err
}
cfg.nextLocationsURL = locationsResp.Next
cfg.prevLocationsURL = locationsResp.Previous
for _, loc := range locationsResp.Results {
fmt.Println(loc.Name)
}
return nil
}
func commandMapb(cfg *config, args ...string) error {
if cfg.prevLocationsURL == nil {
return errors.New("you're on the first page")
}
locationResp, err := cfg.pokeapiClient.ListLocations(cfg.prevLocationsURL)
if err != nil {
return err
}
cfg.nextLocationsURL = locationResp.Next
cfg.prevLocationsURL = locationResp.Previous
for _, loc := range locationResp.Results {
fmt.Println(loc.Name)
}
return nil
}