aboutsummaryrefslogtreecommitdiff
path: root/api/routes.go
diff options
context:
space:
mode:
authorjackyzha0 <[email protected]>2020-05-09 20:15:59 -0700
committerjackyzha0 <[email protected]>2020-05-09 20:15:59 -0700
commitdedabf41a18820527aed9e77b75564e69c9030ce (patch)
tree9258832576f9c1bcad6126cf76ef8f7f6a128e82 /api/routes.go
parentMerge pull request #3 from jackyzha0/doc-expiry (diff)
downloadctrl-v-dedabf41a18820527aed9e77b75564e69c9030ce.tar.xz
ctrl-v-dedabf41a18820527aed9e77b75564e69c9030ce.zip
folder refactor
Diffstat (limited to 'api/routes.go')
-rw-r--r--api/routes.go58
1 files changed, 0 insertions, 58 deletions
diff --git a/api/routes.go b/api/routes.go
deleted file mode 100644
index 760ee35..0000000
--- a/api/routes.go
+++ /dev/null
@@ -1,58 +0,0 @@
-package api
-
-import (
- "encoding/json"
- "fmt"
- "net/http"
- "time"
-
- "github.com/gorilla/mux"
- "github.com/jackyzha0/ctrl-v/cache"
- "github.com/jackyzha0/ctrl-v/db"
-
- log "github.com/sirupsen/logrus"
-)
-
-func healthCheckFunc(w http.ResponseWriter, r *http.Request) {
- fmt.Fprint(w, "status ok")
-}
-
-func insertFunc(w http.ResponseWriter, r *http.Request) {
- // get content
- _ = r.ParseMultipartForm(0)
- expiry := r.FormValue("expiry")
- content := r.FormValue("content")
-
- // get ip
- ip := getIP(r)
-
- log.Infof("got content '%s' and ip '%s'", content, ip)
-
- // insert content
- err := db.New(ip, content, expiry)
- if err != nil {
- fmt.Fprintf(w, "got err: %s", err.Error())
- }
-}
-
-func getHashFunc(w http.ResponseWriter, r *http.Request) {
- hash := mux.Vars(r)["hash"]
- paste, err := cache.C.Get(hash)
-
- // if hash was not found
- if err != nil {
- w.WriteHeader(http.StatusNotFound)
- fmt.Fprintf(w, "got err: %s", err.Error())
- return
- }
-
- // otherwise, return paste content and current time
- w.Header().Set("Content-Type", "application/json")
- pasteMap := map[string]interface{}{
- "timestamp": time.Now(),
- "content": paste.Content,
- }
-
- jsonData, _ := json.Marshal(pasteMap)
- fmt.Fprintf(w, "%+v", string(jsonData))
-}