From 98bea91edf091544fb8b17c9908d51304bbc1c49 Mon Sep 17 00:00:00 2001 From: Henrique Dias Date: Sun, 20 Aug 2017 09:27:03 +0100 Subject: [PATCH] Add Comments Former-commit-id: ea1761b1e1bd9ff6eb80e06ff378d8263de86064 [formerly a4cefe6cf2f1da416ad34175bcea96ac5262d766] [formerly cc4c6afca638a66e223e64a6bffde563a48b1990 [formerly c6e6b0830505724aab779859c56a9cdb55fa9016]] Former-commit-id: 56c1574b23fefd33b41d848f47201a24e75d9e6b [formerly b326f699ef7dde08a4e81b4a3a7db22902270634] Former-commit-id: 078a180adea8d3f3f02177caf78cbeea22145d4c --- bolt/config.go | 3 +++ bolt/share.go | 7 +++++++ bolt/users.go | 6 ++++++ 3 files changed, 16 insertions(+) diff --git a/bolt/config.go b/bolt/config.go index eab21f1b..e3d7fb81 100644 --- a/bolt/config.go +++ b/bolt/config.go @@ -5,10 +5,12 @@ import ( fm "github.com/hacdias/filemanager" ) +// ConfigStore is a configuration store. type ConfigStore struct { DB *storm.DB } +// Get gets a configuration from the database to an interface. func (c ConfigStore) Get(name string, to interface{}) error { err := c.DB.Get("config", name, to) if err == storm.ErrNotFound { @@ -18,6 +20,7 @@ func (c ConfigStore) Get(name string, to interface{}) error { return err } +// Save saves a configuration from an interface to the database. func (c ConfigStore) Save(name string, from interface{}) error { return c.DB.Set("config", name, from) } diff --git a/bolt/share.go b/bolt/share.go index 189ed418..cbe6eed5 100644 --- a/bolt/share.go +++ b/bolt/share.go @@ -6,10 +6,12 @@ import ( fm "github.com/hacdias/filemanager" ) +// ShareStore is a shareable links store. type ShareStore struct { DB *storm.DB } +// Get gets a Share Link from an hash. func (s ShareStore) Get(hash string) (*fm.ShareLink, error) { var v *fm.ShareLink err := s.DB.One("Hash", hash, &v) @@ -20,6 +22,7 @@ func (s ShareStore) Get(hash string) (*fm.ShareLink, error) { return v, err } +// GetPermanent gets the permanent link from a path. func (s ShareStore) GetPermanent(path string) (*fm.ShareLink, error) { var v *fm.ShareLink err := s.DB.Select(q.Eq("Path", path), q.Eq("Expires", false)).First(&v) @@ -30,6 +33,7 @@ func (s ShareStore) GetPermanent(path string) (*fm.ShareLink, error) { return v, err } +// GetByPath gets all the links for a specific path. func (s ShareStore) GetByPath(hash string) ([]*fm.ShareLink, error) { var v []*fm.ShareLink err := s.DB.Find("Path", hash, &v) @@ -40,16 +44,19 @@ func (s ShareStore) GetByPath(hash string) ([]*fm.ShareLink, error) { return v, err } +// Gets retrieves all the shareable links. func (s ShareStore) Gets() ([]*fm.ShareLink, error) { var v []*fm.ShareLink err := s.DB.All(&v) return v, err } +// Save stores a Share Link on the database. func (s ShareStore) Save(l *fm.ShareLink) error { return s.DB.Save(l) } +// Delete deletes a Share Link from the database. func (s ShareStore) Delete(hash string) error { return s.DB.DeleteStruct(&fm.ShareLink{Hash: hash}) } diff --git a/bolt/users.go b/bolt/users.go index 2c12f69a..55758614 100644 --- a/bolt/users.go +++ b/bolt/users.go @@ -7,10 +7,12 @@ import ( fm "github.com/hacdias/filemanager" ) +// UsersStore is a users store. type UsersStore struct { DB *storm.DB } +// Get gets a user with a certain id from the database. func (u UsersStore) Get(id int, builder fm.FSBuilder) (*fm.User, error) { var us *fm.User err := u.DB.One("ID", id, us) @@ -26,6 +28,7 @@ func (u UsersStore) Get(id int, builder fm.FSBuilder) (*fm.User, error) { return us, nil } +// Gets gets all the users from the database. func (u UsersStore) Gets(builder fm.FSBuilder) ([]*fm.User, error) { var us []*fm.User err := u.DB.All(us) @@ -40,6 +43,7 @@ func (u UsersStore) Gets(builder fm.FSBuilder) ([]*fm.User, error) { return us, err } +// Updates the whole user object or only certain fields. func (u UsersStore) Update(us *fm.User, fields ...string) error { if len(fields) == 0 { return u.Save(us) @@ -55,10 +59,12 @@ func (u UsersStore) Update(us *fm.User, fields ...string) error { return nil } +// Save saves a user to the database. func (u UsersStore) Save(us *fm.User) error { return u.DB.Save(us) } +// Delete deletes a user from the database. func (u UsersStore) Delete(id int) error { return u.DB.DeleteStruct(&fm.User{ID: id}) }