forked from brianvoe/gofakeit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbook.go
85 lines (67 loc) · 2.28 KB
/
book.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package gofakeit
import "math/rand"
func BookTitle() string { return bookTitle(globalFaker.Rand) }
func (f *Faker) BookTitle() string { return bookTitle(f.Rand) }
func bookTitle(r *rand.Rand) string { return getRandValue(r, []string{"book", "title"}) }
func BookAuthor() string { return bookAuthor(globalFaker.Rand) }
func (f *Faker) BookAuthor() string { return bookAuthor(f.Rand) }
func bookAuthor(r *rand.Rand) string { return getRandValue(r, []string{"book", "author"}) }
func BookGenre() string { return bookGenre(globalFaker.Rand) }
func (f *Faker) BookGenre() string { return bookGenre(f.Rand) }
func bookGenre(r *rand.Rand) string { return getRandValue(r, []string{"book", "genre"}) }
type BookInfo struct {
Title string `json:"title" xml:"name"`
Author string `json:"author" xml:"author"`
Genre string `json:"genre" xml:"genre"`
}
func Book() *BookInfo { return book(globalFaker.Rand) }
func (f *Faker) Book() *BookInfo { return book(f.Rand) }
func book(r *rand.Rand) *BookInfo {
return &BookInfo{
Title: bookTitle(r),
Author: bookAuthor(r),
Genre: bookGenre(r),
}
}
func addBookLookup() {
AddFuncLookup("book", Info{
Display: "Book",
Category: "book",
Description: "Random Book data set",
Example: `{title: "Hamlet", author: "Mark Twain", genre: "Adventure"}`,
Output: "map[string]string",
Generate: func(r *rand.Rand, m *MapParams, info *Info) (interface{}, error) {
return book(r), nil
},
})
AddFuncLookup("booktitle", Info{
Display: "Title",
Category: "book",
Description: "Random Book title",
Example: "Hamlet",
Output: "string",
Generate: func(r *rand.Rand, m *MapParams, info *Info) (interface{}, error) {
return bookTitle(r), nil
},
})
AddFuncLookup("bookauthor", Info{
Display: "Author",
Category: "book",
Description: "Random Book author",
Example: "Mark Twain",
Output: "string",
Generate: func(r *rand.Rand, m *MapParams, info *Info) (interface{}, error) {
return bookAuthor(r), nil
},
})
AddFuncLookup("bookgenre", Info{
Display: "Genre",
Category: "book",
Description: "Random Book genre",
Example: "Adventure",
Output: "string",
Generate: func(r *rand.Rand, m *MapParams, info *Info) (interface{}, error) {
return bookGenre(r), nil
},
})
}