-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
59 lines (48 loc) · 1.05 KB
/
main.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package main
import (
"flag"
"fmt"
"log"
"math/rand"
"time"
"github.com/knq/dburl"
)
var (
flagVerbose = flag.Bool("v", false, "toggle verbose")
flagURL = flag.String("url", "", "database url")
flagSeed = flag.Int64("seed", time.Now().UnixNano(), "rand seed")
)
func main() {
var err error
flag.Parse()
// set verbose
if *flagVerbose {
XOLog = func(s string, p ...interface{}) {
fmt.Printf("-------------------------------------\nQUERY: %s\n VAL: %v\n", s, p)
}
}
// open database
db, err := dburl.Open(*flagURL)
if err != nil {
log.Fatal(err)
}
// get random id
r := rand.New(rand.NewSource(*flagSeed))
id := r.Intn(720) + 1
// lookup pokemon
log.Printf("looking up pokemon with id %d", id)
p, err := PokemonByID(db, id)
if err != nil {
log.Fatal(err)
}
// get the pokemon's species
species, err := p.PokemonSpecies(db)
if err != nil {
log.Fatal(err)
}
// display
log.Printf(
"pokemon #%d: `%s` (species: `%s`, height: %d, weight: %d)\n",
p.ID, p.Identifier, species.Identifier, p.Height, p.Weight,
)
}