-
Notifications
You must be signed in to change notification settings - Fork 0
/
command_map.go
41 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
package main
import (
"errors"
"fmt"
//"encoding/json"
//"github.com/adamthiede/bootdev-pokedex/internal/pokeapi"
)
func commandMap(cfg *config, args ...string) error {
resp, err := cfg.pokeApiClient.ListLocationAreas(cfg.nextLocationAreaURL)
if err != nil {
return err
}
for _, area := range resp.Results {
fmt.Printf(" - %s\n", area.Name)
}
cfg.nextLocationAreaURL = resp.Next
cfg.prevLocationAreaURL = resp.Previous
return nil
}
func commandMapb(cfg *config, args ...string) error {
if cfg.prevLocationAreaURL == nil {
return errors.New("no previous page")
}
resp, err := cfg.pokeApiClient.ListLocationAreas(cfg.prevLocationAreaURL)
if err != nil {
return err
}
for _, area := range resp.Results {
fmt.Printf(" - %s\n", area.Name)
}
cfg.nextLocationAreaURL = resp.Next
cfg.prevLocationAreaURL = resp.Previous
return nil
}