示例#1
0
文件: images.go 项目: dimiro1/faker
// 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)
}
示例#2
0
文件: internet.go 项目: dimiro1/faker
// 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)
}
示例#3
0
文件: internet.go 项目: dimiro1/faker
// 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)
}
示例#4
0
文件: internet.go 项目: dimiro1/faker
// 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)
}
示例#5
0
文件: images.go 项目: dimiro1/faker
// 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)
}