forked from brianvoe/gofakeit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
book.go
88 lines (71 loc) · 2.38 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
86
87
88
package gofakeit
func BookTitle() string { return bookTitle(GlobalFaker) }
func (f *Faker) BookTitle() string { return bookTitle(f) }
func bookTitle(f *Faker) string { return getRandValue(f, []string{"book", "title"}) }
func BookAuthor() string { return bookAuthor(GlobalFaker) }
func (f *Faker) BookAuthor() string { return bookAuthor(f) }
func bookAuthor(f *Faker) string { return getRandValue(f, []string{"book", "author"}) }
func BookGenre() string { return bookGenre(GlobalFaker) }
func (f *Faker) BookGenre() string { return bookGenre(f) }
func bookGenre(f *Faker) string { return getRandValue(f, []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) }
func (f *Faker) Book() *BookInfo { return book(f) }
func book(f *Faker) *BookInfo {
return &BookInfo{
Title: bookTitle(f),
Author: bookAuthor(f),
Genre: bookGenre(f),
}
}
func addBookLookup() {
AddFuncLookup("book", Info{
Display: "Book",
Category: "book",
Description: "Written or printed work consisting of pages bound together, covering various subjects or stories",
Example: `{
"title": "Anna Karenina",
"author": "Toni Morrison",
"genre": "Thriller"
}`,
Output: "map[string]string",
ContentType: "application/json",
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
return book(f), nil
},
})
AddFuncLookup("booktitle", Info{
Display: "Title",
Category: "book",
Description: "The specific name given to a book",
Example: "Hamlet",
Output: "string",
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
return bookTitle(f), nil
},
})
AddFuncLookup("bookauthor", Info{
Display: "Author",
Category: "book",
Description: "The individual who wrote or created the content of a book",
Example: "Mark Twain",
Output: "string",
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
return bookAuthor(f), nil
},
})
AddFuncLookup("bookgenre", Info{
Display: "Genre",
Category: "book",
Description: "Category or type of book defined by its content, style, or form",
Example: "Adventure",
Output: "string",
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
return bookGenre(f), nil
},
})
}