forked from go-chi/chi
-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
33 lines (26 loc) · 819 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
//
// Todos Resource
// ==============
// This example demonstrates a project structure that defines a subrouter and its
// handlers on a struct, and mounting them as subrouters to a parent router.
// See also _examples/rest for an in-depth example of a REST service, and apply
// those same patterns to this structure.
//
package main
import (
"context"
"github.com/swaggest/fchi"
"github.com/swaggest/fchi/middleware"
"github.com/valyala/fasthttp"
)
func main() {
r := fchi.NewRouter()
r.Use(middleware.RequestID)
r.Use(middleware.Recoverer)
r.Get("/", fchi.HandlerFunc(func(ctx context.Context, rc *fasthttp.RequestCtx) {
rc.Write([]byte("."))
}))
r.Mount("/users", usersResource{}.Routes())
r.Mount("/todos", todosResource{}.Routes())
fasthttp.ListenAndServe(":3333", fchi.RequestHandler(r))
}