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