mirror of
https://github.com/hay-kot/homebox.git
synced 2024-11-16 21:58:40 +00:00
bd321af29f
* new PR tasks * add homebox to know words * formatting * bump deps * generate db models * ts errors * drop id * fix accessor * drop unused time field * change CI * add expected error * add type check * resolve serveral type errors * hoise in CI
43 lines
783 B
Go
43 lines
783 B
Go
package faker
|
|
|
|
import (
|
|
"math/rand"
|
|
"time"
|
|
)
|
|
|
|
var letters = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
|
|
|
|
type Faker struct{}
|
|
|
|
func NewFaker() *Faker {
|
|
rand.Seed(time.Now().UnixNano())
|
|
return &Faker{}
|
|
}
|
|
|
|
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 {
|
|
b := make([]rune, length)
|
|
for i := range b {
|
|
b[i] = letters[rand.Intn(len(letters))]
|
|
}
|
|
return string(b)
|
|
}
|
|
|
|
func (f *Faker) Path() string {
|
|
return "/" + f.Str(10) + "/" + f.Str(10) + "/" + f.Str(10)
|
|
}
|
|
|
|
func (f *Faker) Email() string {
|
|
return f.Str(10) + "@example.com"
|
|
}
|
|
|
|
func (f *Faker) Bool() bool {
|
|
return rand.Intn(2) == 1
|
|
}
|
|
|
|
func (f *Faker) Num(min, max int) int {
|
|
return rand.Intn(max-min) + min
|
|
}
|