-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhandlers.go
38 lines (30 loc) · 818 Bytes
/
handlers.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
package gosvelt
import (
"fmt"
"github.com/valyala/fasthttp"
)
var defaultErrorHandler = func(c *fasthttp.RequestCtx, err error) {
fmt.Printf("[%s] -> %v\n", c.Path(), err)
c.Write([]byte(err.Error()))
}
type HandlerFunc func(c *Context) error
type MiddlewareFunc func(next HandlerFunc) HandlerFunc
type SvelteMiddlewareFunc func(next SvelteHandlerFunc) SvelteHandlerFunc
type SvelteHandlerFunc func(c *Context, svelte Map) error
type ErrorHandlerFunc func(c *fasthttp.RequestCtx, err error)
func Status(code int) HandlerFunc {
return func(c *Context) error {
c.SetStatusCode(code)
return nil
}
}
func String(str string) HandlerFunc {
return func(c *Context) error {
return c.Text(200, str)
}
}
func Json(j interface{}) HandlerFunc {
return func(c *Context) error {
return c.Json(200, j)
}
}