@ -11,6 +11,7 @@ type Namespace struct {
LastSeen time.Time
AllowanceDuration time.Duration
FileQuota FileSizeQuota
Usage Usage
}
var (
@ -32,3 +32,28 @@ func (f *FileSizeQuota) Remove(size int64) error {
return nil
type Usage struct {
Uploads int64
UploadB int64
Downloads int64
DownloadB int64
func (u Usage) Uploaded(size int64) Usage {
return Usage{
u.Uploads + 1,
u.UploadB + size,
u.Downloads,
u.DownloadB,
func (u Usage) Downloaded(size int64) Usage {
u.Uploads,
u.UploadB,
u.Downloads + 1,
u.DownloadB + size,
@ -38,6 +38,7 @@ func (s SwampFileService) getOrCreateNs(namespace_in string) *namespace.Namespac
time.Now(),
s.default_allowance_duration,
namespace.FileSizeQuota{s.default_allowance_bytes, 0},
namespace.Usage{0, 0, 0, 0},
created_ns, err := s.namespace_repo.Create(new_ns)
@ -16,7 +16,14 @@ func TestUserAgentRepo(t *testing.T) {
is.NoErr(err)
is.Equal(len(all), 0)
ns := namespace.Namespace{23, "n1", time.Now(), time.Duration(time.Hour * 3), namespace.FileSizeQuota{1000, 0}}
ns := namespace.Namespace{
23,
"n1",
time.Duration(time.Hour * 3),
namespace.FileSizeQuota{1000, 0},
ns1, _ := r.Create(ns)
ns.Name = "n2"