-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
53 lines (45 loc) · 1.16 KB
/
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
45
46
47
48
49
50
51
52
53
package main
import (
"fmt"
"net/http"
"github.com/go-chi/chi"
"github.com/go-chi/chi/middleware"
"github.com/go-chi/cors"
"github.com/finest08/jwt-auth-demo/handler"
"github.com/finest08/jwt-auth-demo/store"
)
func main() {
s := store.Connect()
r := chi.NewRouter()
r.Use(
middleware.Logger,
middleware.StripSlashes,
cors.Handler(cors.Options{
AllowedOrigins: []string{"https://*", "http://*"},
AllowedMethods: []string{"GET", "POST", "PUT", "DELETE", "OPTIONS", "QUERY"},
AllowedHeaders: []string{"Accept", "Authorization", "Content-Type", "X-CSRF-Token"},
ExposedHeaders: []string{"Link"},
AllowCredentials: true,
MaxAge: 300,
}),
)
p := &handler.Person{
Store: s,
}
r.Route("/person", func(r chi.Router) {
r.With().Post("/create", p.Create)
})
r.Route("/login", func(r chi.Router) {
r.With().Post("/", p.Login)
})
r.Route("/auth", func(r chi.Router) {
r.With().Get("/people", p.Query)
r.With().Get("/user", p.Auth)
r.With().Get("/{id}", p.Get)
r.With().Patch("/{id}", p.Update)
r.With().Delete("/{id}", p.Delete)
})
if err := http.ListenAndServe(":8080", r); err != nil {
fmt.Print(err)
}
}