forked from awslabs/aws-lambda-go-api-proxy
/
pets.go
61 lines (47 loc) · 1.49 KB
/
pets.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
60
61
package main
import (
"log"
"math/rand"
"time"
"github.com/google/uuid"
)
var breeds = []string{"Afghan Hound", "Beagle", "Bernese Mountain Dog", "Bloodhound", "Dalmatian", "Jack Russell Terrier", "Norwegian Elkhound"}
var names = []string{"Bailey", "Bella", "Max", "Lucy", "Charlie", "Molly", "Buddy", "Daisy", "Rocky", "Maggie", "Jake", "Sophie", "Jack", "Sadie", "Toby", "Chloe", "Cody", "Bailey", "Buster", "Lola", "Duke", "Zoe", "Cooper", "Abby", "Riley", "Ginger", "Harley", "Roxy", "Bear", "Gracie", "Tucker", "Coco", "Murphy", "Sasha", "Lucky", "Lily", "Oliver", "Angel", "Sam", "Princess", "Oscar", "Emma", "Teddy", "Annie", "Winston", "Rosie"}
type Pet struct {
ID string `json:"id"`
Breed string `json:"breed"`
Name string `json:"name"`
DateOfBirth time.Time `json:"dateOfBirth"`
}
func getRandomPet() Pet {
pet := Pet{}
pet.ID = getUUID()
pet.Breed = randomBreed()
pet.Name = randomName()
pet.DateOfBirth = randomDate()
return pet
}
func randomDate() time.Time {
now := time.Now()
start := now.AddDate(-15, 0, 0)
delta := now.Unix() - start.Unix()
sec := rand.Int63n(delta) + start.Unix()
return time.Unix(sec, 0)
}
func randomBreed() string {
return breeds[random(0, len(breeds))]
}
func randomName() string {
return names[random(0, len(names))]
}
func random(min int, max int) int {
return rand.Intn(max-min) + min
}
func getUUID() string {
uuid, err := uuid.NewRandom()
if err != nil {
log.Fatal(err)
return ""
}
return uuid.String()
}