indiescrobble/models/user.go

34 lines
516 B
Go
Raw Normal View History

2022-02-19 15:47:25 +00:00
package models
import (
"math/rand"
"gorm.io/gorm"
)
var alphanum = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890")
func randSeq(n int) string {
b := make([]rune, n)
for i := range b {
b[i] = alphanum[rand.Intn(len(alphanum))]
}
return string(b)
}
type BaseUser struct {
Me string
Token string
UserRecord *User
}
type User struct {
gorm.Model
Me string `gorm:"uniqueIndex"`
APIKey string
}
func (u *User) GenerateRandomKey() {
u.APIKey = randSeq(16)
}