aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjackyzha0 <[email protected]>2020-05-09 12:55:48 -0700
committerjackyzha0 <[email protected]>2020-05-09 12:55:48 -0700
commita797d6f4798c8794dfe45fb745ecadd659ad77e5 (patch)
treeeedf0601b321c2536bf5c87777cc5bc7d67f2736
parentworking con to mongo (diff)
downloadctrl-v-a797d6f4798c8794dfe45fb745ecadd659ad77e5.tar.xz
ctrl-v-a797d6f4798c8794dfe45fb745ecadd659ad77e5.zip
outline insert op
-rw-r--r--db/db.go15
-rw-r--r--db/mongo.go8
2 files changed, 21 insertions, 2 deletions
diff --git a/db/db.go b/db/db.go
index c170af3..5c35495 100644
--- a/db/db.go
+++ b/db/db.go
@@ -20,3 +20,18 @@ func init() {
initSessions(mUser, mPass, mIP)
}
+
+// creates a new
+func New(hash, content string) error {
+
+ // create new struct
+ new := Paste{
+ Hash: hash,
+ Content: content,
+ }
+
+ // insert struct
+ log.Infof("create new paste with hash %s", hash)
+ insertErr := insert(new)
+ return insertErr
+}
diff --git a/db/mongo.go b/db/mongo.go
index 4c3b88a..c3e31dd 100644
--- a/db/mongo.go
+++ b/db/mongo.go
@@ -10,7 +10,7 @@ import (
)
var Session *mgo.Session
-var TextDB *mgo.Collection
+var pastes *mgo.Collection
func initSessions(user, pass, ip string) {
log.Infof("attempting connection to %s", ip)
@@ -35,5 +35,9 @@ func initSessions(user, pass, ip string) {
}
// Define connection to Databases
- TextDB = Session.DB("main").C("pastes")
+ pastes = Session.DB("main").C("pastes")
+}
+
+func insert(new Paste) error {
+ return pastes.Insert(new)
}