-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
44 lines (34 loc) · 817 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package main
import (
"net/http"
"github.com/gin-gonic/gin"
"github.com/google/uuid"
)
func main() {
secrets := make(map[string]string)
r := gin.Default()
r.LoadHTMLGlob("html/*")
r.GET("/note/:hash", func(c *gin.Context) {
hash := c.Params.ByName("hash")
if val, ok := secrets[hash]; ok {
c.HTML(http.StatusOK, "note.tmpl", gin.H{
"note": val,
})
delete(secrets, hash)
} else {
c.String(http.StatusNotFound, "Not Found")
}
})
r.GET("/", func(c *gin.Context) {
c.HTML(http.StatusOK, "index.tmpl", map[string]interface{}{})
})
r.POST("/share", func(c *gin.Context) {
note := c.PostForm("note")
key := uuid.New().String()
secrets[key] = note
c.HTML(http.StatusOK, "share.tmpl", gin.H{
"url": c.Request.Host + "/note/" + key,
})
})
r.Run("localhost:8080")
}