forked from mirrors/homebox
95ab14b866
* format readme * update logo * format html * add logo to docs * repository for document and document tokens * add attachments type and repository * autogenerate types via scripts * use autogenerated types * attachment type updates * add insured and quantity fields for items * implement HasID interface for entities * implement label updates for items * implement service update method * WIP item update client side actions * check err on attachment * finish types for basic items editor * remove unused var * house keeping
45 lines
784 B
Go
45 lines
784 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) + "@email.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
|
|
}
|