Beispiel #1
0
// PlaceholderImageWithOptions returns a Placeholder image
func (f Faker) PlaceholderImageWithOptions(o ImageOptions) string {
	defaults.Apply(&o)

	formats := []string{".jpeg", ".jpg", ".gif", ".png"}
	valid := false

	for _, format := range formats {
		if o.Format == format {
			valid = true
		}
	}

	if !valid {
		panic(fmt.Sprintf("images: %s is an invalid format, valid formats are %s", o.Format, formats))
	}

	size := strings.Split(o.Size, "x")

	if len(size) != 2 {
		panic(fmt.Sprintf("images: %s is an invalid size, valid format is 300x300", o.Size))
	}

	width := size[0]
	height := size[1]

	return fmt.Sprintf("http://placehold.it/%sx%s%s", width, height, o.Format)
}
Beispiel #2
0
// UserNameWithOptions returns a username with the default options
func (f Faker) UserNameWithOptions(o UserNameOptions) string {
	defaults.Apply(&o)

	var words []string

	for _, word := range strings.Split(o.Name, " ") {
		words = append(words, strings.ToLower(word))
	}

	return strings.Join(words, o.Sep)
}
Beispiel #3
0
// FreeEmailWithOptions returns a safe email with the options
func (f Faker) FreeEmailWithOptions(o EmailOptions) string {
	defaults.Apply(&o)

	if o.Name == "" {
		panic("faker: '' is not a valid username for email")
	}

	username := f.UserNameWithOptions(UserNameOptions{Name: o.Name})
	domain := randomElement(freeEmailDomains)

	return fmt.Sprintf("%s@%s", username, domain)
}
Beispiel #4
0
// PasswordWithOptions returns password defined by the options
func (f Faker) PasswordWithOptions(o PassWordOptions) string {
	defaults.Apply(&o)

	var pass string

	if o.Alpha {
		pass = fillString("*", o.Length)
	} else {
		pass = fillString("#", o.Length)
	}

	return format(pass)
}
Beispiel #5
0
// AvatarImageWithOptions returns a AvatarImage image
func (f Faker) AvatarImageWithOptions(o AvatarOptions) string {
	defaults.Apply(&o)

	if o.Email == "" {
		panic(fmt.Sprintf("images: %s is empty", o.Email))
	}

	formats := []string{".jpg", ".png"}
	valid := false

	for _, format := range formats {
		if o.Format == format {
			valid = true
		}
	}

	if !valid {
		panic(fmt.Sprintf("images: %s is an invalid format, valid formats are %s", o.Format, formats))
	}

	return fmt.Sprintf("http://api.adorable.io/avatars/%s/%s%s", o.Size, o.Email, o.Format)
}