summaryrefslogtreecommitdiffhomepage
path: root/http/router.go
diff options
context:
space:
mode:
Diffstat (limited to 'http/router.go')
-rw-r--r--http/router.go23
1 files changed, 23 insertions, 0 deletions
diff --git a/http/router.go b/http/router.go
new file mode 100644
index 0000000..f1a0b47
--- /dev/null
+++ b/http/router.go
@@ -0,0 +1,23 @@
+package http
+
+import (
+ "github.com/fasthttp/router"
+ "github.com/valyala/fasthttp"
+ "toast.cafe/x/brpaste/v2/storage"
+)
+
+// GenHandler generates the brpaste handler
+func GenHandler(store storage.CHR) func(ctx *fasthttp.RequestCtx) {
+ get := Get(store)
+ post := Put(store, false)
+ put := Put(store, true)
+
+ r := router.New()
+ r.GET("/", Index)
+ r.GET("/:key", get)
+ r.GET("/:key/:lang", get)
+ r.POST("/", post)
+ r.PUT("/:key", put)
+
+ return r.Handler
+}