-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinternet.go
59 lines (50 loc) · 1.65 KB
/
internet.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 faker
func (f *Faker) Email() (mail string) {
check := func(provider *Provider) bool {
return provider.Internet == nil || len(provider.Internet.FreeEmailDomains) == 0
}
p := f.GetProviderWithCheck(check)
var userNameFormatTemplate, emailFormatTemplate string
if p.Internet != nil {
if len(p.Internet.UserNameFormatTemplates) > 0 {
userNameFormatTemplate = f.RandomStringElement(p.Internet.UserNameFormatTemplates)
} else {
userNameFormatTemplate = "{{.LastName}}{{.FirstName}}"
}
if p.Internet.EmailFormatTemplate != "" {
emailFormatTemplate = p.Internet.EmailFormatTemplate
} else {
emailFormatTemplate = "{{.UserName}}@{{.EmailDomain}}"
}
}
return f.Format(emailFormatTemplate, map[string]interface{}{
"UserName": f.Format(userNameFormatTemplate, map[string]interface{}{
"LastName": f.PersonFirstNameWithI18nLanguage(I18nLanguageEnUs),
"FirstName": f.PersonLastNameWithI18nLanguage(I18nLanguageEnUs),
}),
"EmailDomain": f.RandomStringElement(p.Internet.FreeEmailDomains),
})
}
func (f *Faker) Image(width, height uint32) string {
const (
maxWidth = 1024
maxHeight = 1024
)
check := func(provider *Provider) bool {
return provider.Internet == nil || len(provider.Internet.ImagePlaceholderServiceTemplateList) == 0
}
p := f.GetProviderWithCheck(check)
if check(p) {
return ""
}
if width <= 0 || width > maxWidth {
width = uint32(f.IntBetween(1, maxWidth))
}
if height <= 0 || height > maxHeight {
height = uint32(f.IntBetween(1, maxHeight))
}
return f.Format(f.RandomStringElement(p.Internet.ImagePlaceholderServiceTemplateList), map[string]interface{}{
"WIDTH": width,
"HEIGHT": height,
})
}