summaryrefslogtreecommitdiff
path: root/main.go
diff options
context:
space:
mode:
Diffstat (limited to 'main.go')
-rw-r--r--main.go38
1 files changed, 38 insertions, 0 deletions
diff --git a/main.go b/main.go
new file mode 100644
index 0000000..1b5dd5b
--- /dev/null
+++ b/main.go
@@ -0,0 +1,38 @@
+package main
+
+import (
+ "encoding/json"
+ "github.com/gorilla/mux"
+ "log"
+ "net/http"
+)
+
+func handleEntry(w http.ResponseWriter, r *http.Request) {
+ var entry Entry
+
+ err := json.NewDecoder(r.Body).Decode(&entry)
+ if err != nil {
+ http.Error(w, err.Error(), http.StatusBadRequest)
+ return
+ }
+
+ err = InsertEntry(&entry)
+ if err != nil {
+ http.Error(w, err.Error(), http.StatusInternalServerError)
+ return
+ }
+}
+
+func handleRequests() {
+ router := mux.NewRouter()
+ router.HandleFunc("/entry", handleEntry).Methods("POST")
+
+ log.Fatal(http.ListenAndServe(":8080", router))
+}
+
+func main() {
+ log.Println("Starting up")
+ InitEntries()
+ defer CloseEntries()
+ handleRequests()
+}