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.
bog/dataswamp/namespace/valueobjects.go

32 lines
475 B
Go

package namespace
type FileSizeQuota struct {
AllowanceKB int64
CurrentUsage int64
}
func (f *FileSizeQuota) Allows(size int64) bool {
return f.CurrentUsage + size <= f.AllowanceKB
}
func (f *FileSizeQuota) Add(size int64) error {
if !f.Allows(size) {
return ErrExceedQuota
}
f.CurrentUsage += size
return nil
}
func (f *FileSizeQuota) Remove(size int64) error {
if size > f.CurrentUsage {
return ErrQuotaInvalid
}
f.CurrentUsage -= size
return nil
}