2022-08-30 02:30:36 +00:00
|
|
|
package faker
|
|
|
|
|
|
|
|
import (
|
|
|
|
"math/rand"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
var letters = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
|
|
|
|
|
2023-02-18 06:41:01 +00:00
|
|
|
type Faker struct{}
|
2022-08-30 02:30:36 +00:00
|
|
|
|
|
|
|
func NewFaker() *Faker {
|
|
|
|
return &Faker{}
|
|
|
|
}
|
|
|
|
|
2022-09-12 22:47:27 +00:00
|
|
|
func (f *Faker) Time() time.Time {
|
|
|
|
return time.Now().Add(time.Duration(f.Num(1, 100)) * time.Hour)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (f *Faker) Str(length int) string {
|
2022-08-30 02:30:36 +00:00
|
|
|
b := make([]rune, length)
|
|
|
|
for i := range b {
|
|
|
|
b[i] = letters[rand.Intn(len(letters))]
|
|
|
|
}
|
|
|
|
return string(b)
|
|
|
|
}
|
|
|
|
|
2022-09-12 22:47:27 +00:00
|
|
|
func (f *Faker) Path() string {
|
|
|
|
return "/" + f.Str(10) + "/" + f.Str(10) + "/" + f.Str(10)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (f *Faker) Email() string {
|
2022-10-13 05:13:07 +00:00
|
|
|
return f.Str(10) + "@example.com"
|
2022-08-30 02:30:36 +00:00
|
|
|
}
|
|
|
|
|
2022-09-12 22:47:27 +00:00
|
|
|
func (f *Faker) Bool() bool {
|
2022-08-30 02:30:36 +00:00
|
|
|
return rand.Intn(2) == 1
|
|
|
|
}
|
|
|
|
|
2022-09-12 22:47:27 +00:00
|
|
|
func (f *Faker) Num(min, max int) int {
|
2022-08-30 02:30:36 +00:00
|
|
|
return rand.Intn(max-min) + min
|
|
|
|
}
|