20 lines
474 B
Go
20 lines
474 B
Go
package models
|
|
|
|
import (
|
|
"github.com/uptrace/bun"
|
|
"golang.org/x/crypto/bcrypt"
|
|
)
|
|
|
|
type User struct {
|
|
bun.BaseModel `bun:"table:c_user"`
|
|
Id int `json:"id" bun:"id,pk,autoincrement"`
|
|
Name string `json:"name"`
|
|
Email string `json:"email"`
|
|
Password string `json:"password"`
|
|
}
|
|
|
|
func (u *User) HashPassword() error {
|
|
tmp, err := bcrypt.GenerateFromPassword([]byte(u.Password), bcrypt.DefaultCost)
|
|
u.Password = string(tmp)
|
|
return err
|
|
}
|