aboutsummaryrefslogtreecommitdiff
path: root/api
diff options
context:
space:
mode:
authorjackyzha0 <[email protected]>2020-05-09 17:40:41 -0700
committerjackyzha0 <[email protected]>2020-05-09 17:40:41 -0700
commit66727df2c1aa369b9250e7596fea6c8ae8385eaa (patch)
tree540dc43adfe6f346490993d5d81b42563aeaeada /api
parentMerge pull request #2 from jackyzha0/api (diff)
downloadctrl-v-66727df2c1aa369b9250e7596fea6c8ae8385eaa.tar.xz
ctrl-v-66727df2c1aa369b9250e7596fea6c8ae8385eaa.zip
add document ttl
Diffstat (limited to 'api')
-rw-r--r--api/routes.go12
1 files changed, 7 insertions, 5 deletions
diff --git a/api/routes.go b/api/routes.go
index ff65e89..760ee35 100644
--- a/api/routes.go
+++ b/api/routes.go
@@ -3,11 +3,11 @@ package api
import (
"encoding/json"
"fmt"
- "github.com/gorilla/mux"
- "github.com/jackyzha0/ctrl-v/cache"
"net/http"
"time"
+ "github.com/gorilla/mux"
+ "github.com/jackyzha0/ctrl-v/cache"
"github.com/jackyzha0/ctrl-v/db"
log "github.com/sirupsen/logrus"
@@ -20,6 +20,7 @@ func healthCheckFunc(w http.ResponseWriter, r *http.Request) {
func insertFunc(w http.ResponseWriter, r *http.Request) {
// get content
_ = r.ParseMultipartForm(0)
+ expiry := r.FormValue("expiry")
content := r.FormValue("content")
// get ip
@@ -28,7 +29,7 @@ func insertFunc(w http.ResponseWriter, r *http.Request) {
log.Infof("got content '%s' and ip '%s'", content, ip)
// insert content
- err := db.New(ip, content)
+ err := db.New(ip, content, expiry)
if err != nil {
fmt.Fprintf(w, "got err: %s", err.Error())
}
@@ -47,10 +48,11 @@ func getHashFunc(w http.ResponseWriter, r *http.Request) {
// otherwise, return paste content and current time
w.Header().Set("Content-Type", "application/json")
- pasteMap := map[string]interface{} {
+ pasteMap := map[string]interface{}{
"timestamp": time.Now(),
- "content": paste.Content,
+ "content": paste.Content,
}
+
jsonData, _ := json.Marshal(pasteMap)
fmt.Fprintf(w, "%+v", string(jsonData))
}