-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommand_map.go
42 lines (34 loc) · 864 Bytes
/
command_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
41
42
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
fmt.Println()
for _, location := range locationsResp.Results {
fmt.Println(location.Name)
}
return nil
}
func commandMapb(cfg *config, args ...string) error {
if cfg.prevLocationsURL == nil {
return errors.New("you're on the first page")
}
locationsResp, err := cfg.pokeapiClient.ListLocations(cfg.prevLocationsURL)
if err != nil {
return err
}
cfg.nextLocationsURL = locationsResp.Next
cfg.prevLocationsURL = locationsResp.Previous
fmt.Println()
for _, location := range locationsResp.Results {
fmt.Println(location.Name)
}
return nil
}