mc_man/util/user.go

51 lines
914 B
Go
Raw Permalink Normal View History

2014-12-21 19:30:42 +00:00
package util
2014-12-29 14:06:24 +00:00
import (
"time"
)
2015-04-23 16:09:59 +00:00
type MCUser struct {
2014-12-21 19:30:42 +00:00
Name string
2014-12-24 17:04:09 +00:00
Index int
2014-12-21 19:30:42 +00:00
IsOp bool
Home string
Porch string
ToJSONString func() string
2014-12-29 14:06:24 +00:00
Quota time.Duration
quotaUsed time.Duration
loginTime time.Time
2014-12-21 19:30:42 +00:00
}
2015-04-23 16:09:59 +00:00
func NewMCUser(nm string) *MCUser {
m := new(MCUser)
2014-12-21 19:30:42 +00:00
m.Name = nm
2014-12-24 17:04:09 +00:00
if nm == "" {
m.Index = -1
}
2014-12-21 19:30:42 +00:00
m.IsOp = false
m.Home = ""
m.Porch = ""
m.Quota = 0
m.quotaUsed = 0
2014-12-21 19:30:42 +00:00
m.ToJSONString = func() string {
return "{\"name\":\"" + m.Name + "\",\"home\":\"" + m.Home + "\",\"porch\":\"" + m.Porch + "\",\"quota\":\"" + m.Quota.String() + "\",\"quota_used\":\"" + m.quotaUsed.String() + "\"}"
2014-12-21 19:30:42 +00:00
}
return m
}
2014-12-29 14:06:24 +00:00
2015-04-23 16:09:59 +00:00
func (u *MCUser) HasQuota() bool {
2014-12-29 14:06:24 +00:00
if u.Quota > 0 {
return u.quotaUsed < u.Quota
} else {
return true
}
}
2015-04-23 16:09:59 +00:00
func (u *MCUser) RemainingQuota() time.Duration {
2014-12-29 14:06:24 +00:00
if u.Quota > 0 {
return u.Quota - u.quotaUsed
} else {
return 0
}
}