mirror of
https://github.com/hay-kot/homebox.git
synced 2024-12-23 15:26:31 +00:00
03df23d97c
* fix inaccruate 401 error on SQL db error
* init golangci-lint config
* linter autofix
* testify auto fixes
* fix sqlite busy errors
* fix naming
* more linter errors
* fix rest of linter issues
Former-commit-id: e8449b3a73
43 lines
832 B
Go
43 lines
832 B
Go
// Package faker provides a simple interface for generating fake data for testing.
|
|
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
|
|
}
|