You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
32 lines
475 B
Go
32 lines
475 B
Go
3 years ago
|
package namespace
|
||
3 years ago
|
|
||
|
|
||
|
type FileSizeQuota struct {
|
||
|
AllowanceKB int64
|
||
|
CurrentUsage int64
|
||
|
}
|
||
|
|
||
|
func (f *FileSizeQuota) Allows(size int64) bool {
|
||
|
return f.CurrentUsage + size <= f.AllowanceKB
|
||
|
}
|
||
|
|
||
3 years ago
|
func (f *FileSizeQuota) Add(size int64) error {
|
||
|
if !f.Allows(size) {
|
||
|
return ErrExceedQuota
|
||
|
}
|
||
|
|
||
3 years ago
|
f.CurrentUsage += size
|
||
3 years ago
|
|
||
|
return nil
|
||
3 years ago
|
}
|
||
|
|
||
3 years ago
|
func (f *FileSizeQuota) Remove(size int64) error {
|
||
|
if size > f.CurrentUsage {
|
||
|
return ErrQuotaInvalid
|
||
|
}
|
||
|
|
||
3 years ago
|
f.CurrentUsage -= size
|
||
3 years ago
|
|
||
|
return nil
|
||
3 years ago
|
}
|