aboutsummaryrefslogtreecommitdiff
path: root/backend/cache
diff options
context:
space:
mode:
authorJacky Zhao <[email protected]>2020-05-10 17:12:23 -0700
committerGitHub <[email protected]>2020-05-10 17:12:23 -0700
commit9c73e3ea82e9a00eecc49db8ee8f10ac030200bd (patch)
tree78f9e2b49ef9ce266c58dad2d26b8fdce2db7ff9 /backend/cache
parentMerge pull request #14 from jackyzha0/readme (diff)
parentAdd auth check to get (diff)
downloadctrl-v-9c73e3ea82e9a00eecc49db8ee8f10ac030200bd.tar.xz
ctrl-v-9c73e3ea82e9a00eecc49db8ee8f10ac030200bd.zip
Merge pull request #12 from jackyzha0/backend
Update post to return hash and password
Diffstat (limited to 'backend/cache')
-rw-r--r--backend/cache/cache.go13
1 files changed, 13 insertions, 0 deletions
diff --git a/backend/cache/cache.go b/backend/cache/cache.go
index bac7ea8..1a8a7a1 100644
--- a/backend/cache/cache.go
+++ b/backend/cache/cache.go
@@ -1,6 +1,7 @@
package cache
import (
+ "errors"
"sync"
"github.com/jackyzha0/ctrl-v/db"
@@ -13,6 +14,9 @@ type Cache struct {
var C *Cache
+var PasteNotFound = errors.New("could not find a paste with that hash")
+var UserUnauthorized = errors.New("paste is password protected")
+
func init() {
C = &Cache{
m: map[string]db.Paste{},
@@ -32,6 +36,15 @@ func (c *Cache) Get(hash string) (db.Paste, error) {
// if it doesnt, lookup from db
p, err := db.Lookup(hash)
+ if err != nil {
+ return p, PasteNotFound
+ }
+
+ // if there is a password
+ if p.Password != "" {
+ return db.Paste{}, UserUnauthorized
+ }
+
c.add(p)
return p, err
}