summaryrefslogtreecommitdiffhomepage
path: root/http/router.go
blob: f1a0b473b77d1557c1b7a2b6f27b586348364a45 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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
}