40 lines
624 B
Go
40 lines
624 B
Go
package models
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/uptrace/bun"
|
|
)
|
|
|
|
type User struct {
|
|
bun.BaseModel `bun:"table:user" json:"-"`
|
|
|
|
Username string `bun:"username,pk"`
|
|
Password string `bun:"password"`
|
|
}
|
|
|
|
type UserState int
|
|
|
|
const (
|
|
UserStateIdle UserState = iota
|
|
UserStateGaming
|
|
)
|
|
|
|
var (
|
|
UserStateStr = []string{"Idle", "Gaming"}
|
|
)
|
|
|
|
type UserStatus struct {
|
|
bun.BaseModel `bun:"table:user_status"`
|
|
|
|
Username string `bun:"username,pk" json:"username"`
|
|
State UserState `bun:"state" json:"state"`
|
|
}
|
|
|
|
func (self UserStatus) View() string {
|
|
return fmt.Sprintf("%s [%s]",
|
|
self.Username,
|
|
UserStateStr[self.State],
|
|
)
|
|
}
|