-
Notifications
You must be signed in to change notification settings - Fork 0
/
command_map.go
36 lines (34 loc) · 942 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
package main
import (
"errors"
"fmt"
)
func callbackMap(cfg *config, args ...string) error {
resp, err :=cfg.pokeapiClient.ListLocationAreas(cfg.nextLocationAreaURL)
if err != nil {
return err
}
fmt.Println("Location areas:")
for _, area := range resp.Results {
fmt.Printf(" - %s\n", area.Name)
}
cfg.nextLocationAreaURL = resp.Next
cfg.prevLocationAreaURL = resp.Previous
return nil
}
func callbackMapb(cfg *config, args ...string) error {
if cfg.prevLocationAreaURL == nil {
return errors.New("you're on the first page")
}
resp, err :=cfg.pokeapiClient.ListLocationAreas(cfg.prevLocationAreaURL)
if err != nil {
return err
}
fmt.Println("Location areas:")
for _, area := range resp.Results {
fmt.Printf(" - %s\n", area.Name)
}
cfg.nextLocationAreaURL = resp.Next
cfg.prevLocationAreaURL = resp.Previous
return nil
}