File tree Expand file tree Collapse file tree 2 files changed +35
-0
lines changed Expand file tree Collapse file tree 2 files changed +35
-0
lines changed Original file line number Diff line number Diff line change @@ -29,3 +29,31 @@ func (f *Faker) Email() (mail string) {
29
29
"EmailDomain" : f .RandomStringElement (p .Internet .FreeEmailDomains ),
30
30
})
31
31
}
32
+
33
+ func (f * Faker ) Image (width , height uint32 ) string {
34
+ const (
35
+ maxWidth = 1024
36
+ maxHeight = 1024
37
+ )
38
+
39
+ check := func (provider * Provider ) bool {
40
+ return provider .Internet == nil || len (provider .Internet .ImagePlaceholderServiceTemplateList ) == 0
41
+ }
42
+ p := f .GetProviderWithCheck (check )
43
+ if check (p ) {
44
+ return ""
45
+ }
46
+
47
+ if width <= 0 || width > maxWidth {
48
+ width = uint32 (f .IntBetween (1 , maxWidth ))
49
+ }
50
+
51
+ if height <= 0 || height > maxHeight {
52
+ height = uint32 (f .IntBetween (1 , maxHeight ))
53
+ }
54
+
55
+ return f .Format (f .RandomStringElement (p .Internet .ImagePlaceholderServiceTemplateList ), map [string ]interface {}{
56
+ "WIDTH" : width ,
57
+ "HEIGHT" : height ,
58
+ })
59
+ }
Original file line number Diff line number Diff line change @@ -23,6 +23,7 @@ type AddressProvider struct {
23
23
type InternetProvider struct {
24
24
FreeEmailDomains , Tlds , UserNameFormatTemplates []string
25
25
EmailFormatTemplate string
26
+ ImagePlaceholderServiceTemplateList []string
26
27
}
27
28
28
29
type PhoneNumberProvider struct {
@@ -72,6 +73,12 @@ func (f *Faker) InitProviderMap() {
72
73
"{{.FirstName}}##" , "?{{.LastName}}" ,
73
74
},
74
75
EmailFormatTemplate : "{{.UserName}}@{{.EmailDomain}}" ,
76
+ ImagePlaceholderServiceTemplateList : []string {
77
+ //"https://www.lorempixel.com/{{.WIDTH}}/{{.HEIGHT}}",
78
+ //"https://dummyimage.com/{{.WIDTH}}/{{.HEIGHT}}",
79
+ "https://placekitten.com/{{.WIDTH}}/{{.HEIGHT}}" ,
80
+ "https://placeimg.com/{{.WIDTH}}/{{.HEIGHT}}/any" ,
81
+ },
75
82
},
76
83
Person : & PersonProvider {
77
84
NameFormatTemplate : "{{.FirstName}}{{.LastName}}" ,
You can’t perform that action at this time.
0 commit comments