2024-06-03 13:01:59 +00:00
|
|
|
package account
|
2024-06-03 11:22:08 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/rs/zerolog/log"
|
|
|
|
"xorm.io/xorm"
|
|
|
|
)
|
|
|
|
|
2024-06-03 13:01:59 +00:00
|
|
|
// Account handler
|
|
|
|
type Account struct {
|
2024-06-03 11:22:08 +00:00
|
|
|
db *xorm.Engine
|
|
|
|
}
|
|
|
|
|
2024-06-03 13:01:59 +00:00
|
|
|
// Account model
|
2024-06-03 11:22:08 +00:00
|
|
|
type Model struct {
|
|
|
|
ID int64
|
2024-06-06 18:17:16 +00:00
|
|
|
Username string `xorm:"varchar(30) unique"`
|
|
|
|
Password string `xorm:"varchar(90)"`
|
|
|
|
Admin bool
|
2024-06-03 11:22:08 +00:00
|
|
|
Created time.Time `xorm:"created"`
|
|
|
|
}
|
|
|
|
|
2024-06-03 13:01:59 +00:00
|
|
|
// Return a new Account
|
|
|
|
func New(engine *xorm.Engine) *Account {
|
2024-06-03 11:22:08 +00:00
|
|
|
// Sync engine
|
|
|
|
err := engine.Sync(new(Model))
|
|
|
|
if err != nil {
|
|
|
|
log.Panic().Msg(err.Error())
|
|
|
|
}
|
|
|
|
|
2024-06-03 13:01:59 +00:00
|
|
|
return &Account{db: engine}
|
2024-06-03 11:22:08 +00:00
|
|
|
}
|