homebox/backend/pkgs/faker/random.go
Hayden faed343eda
fix: cookie-auth-issues (#365)
* fix session clearing on error

* use singleton context to manage user state

* implement remember-me functionality

* fix errors

* fix more errors
2023-03-22 21:52:25 -08:00

42 lines
749 B
Go

package faker
import (
"math/rand"
"time"
)
var letters = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
type Faker struct{}
func NewFaker() *Faker {
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
}