aboutsummaryrefslogtreecommitdiff
path: root/web.go
diff options
context:
space:
mode:
Diffstat (limited to 'web.go')
-rw-r--r--web.go38
1 files changed, 38 insertions, 0 deletions
diff --git a/web.go b/web.go
new file mode 100644
index 0000000..b6ccf48
--- /dev/null
+++ b/web.go
@@ -0,0 +1,38 @@
+package main
+
+import (
+ "fmt"
+ "log"
+ "net/http"
+
+ "github.com/gin-gonic/gin"
+)
+
+func mountRoutes(router *gin.Engine) {
+ router.GET("/", func(c *gin.Context) {
+ c.HTML(http.StatusOK, "index.tmpl", map[string]interface{}{})
+ })
+
+ router.POST("/api/v1/entry", func(c *gin.Context) {
+ formType := c.PostForm("type")
+ formNotes := c.PostForm("notes")
+ formAccessCode := c.PostForm("access_code")
+
+ if formAccessCode == accessCode {
+ log.Println(formType, formNotes, formAccessCode)
+
+ write(formType, formNotes, c.ClientIP())
+
+ c.HTML(http.StatusOK, "notice.tmpl", map[string]interface{}{
+ "Notice": "submission successfully logged",
+ "Data": fmt.Sprintf("{ type: \"%s\", notes: \"%s\" }", formType, formNotes),
+ })
+ } else {
+ log.Printf("invalid access code: %s, expected: %s\n", formAccessCode, accessCode)
+
+ c.HTML(http.StatusUnauthorized, "notice.tmpl", map[string]interface{}{
+ "Notice": "invalid access code",
+ })
+ }
+ })
+}