-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
67 lines (56 loc) · 1.47 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package main
import (
"fmt"
"net/http"
"github.com/mhogar/kiwi/data/adapter"
"github.com/mhogar/kiwi/dependencies"
"github.com/mhogar/kiwi/example/session"
"github.com/mhogar/kiwi/example/user"
"github.com/mhogar/kiwi/nodes/web"
"github.com/julienschmidt/httprouter"
)
func createRouter(adapter adapter.DataAdapter) *httprouter.Router {
r := httprouter.New()
// user routes
r.GET("/user",
web.NewHandler(adapter, user.GetUserEndpoint()).ServeHTTPRouter,
)
r.GET("/user/:username",
web.NewHandler(adapter, user.GetUserEndpoint()).ServeHTTPRouter,
)
r.POST("/user",
web.NewHandler(adapter, user.CreateUserEndpoint()).ServeHTTPRouter,
)
r.PUT("/user",
web.NewHandler(adapter, user.UpdateUserEndpoint()).ServeHTTPRouter,
)
r.PATCH("/user/password",
web.NewHandler(adapter, user.UpdateUserAuthEndpoint()).ServeHTTPRouter,
)
r.DELETE("/user",
web.NewHandler(adapter, user.DeleteUserEndpoint()).ServeHTTPRouter,
)
// session routes
r.POST("/session",
web.NewHandler(adapter, session.CreateSessionEndpoint()).ServeHTTPRouter,
)
r.DELETE("/session",
web.NewHandler(adapter, session.DeleteSessionEndpoint()).ServeHTTPRouter,
)
return r
}
func main() {
adapter := dependencies.DataAdapter.Resolve()
err := adapter.Setup()
if err != nil {
fmt.Println(err.Error())
return
}
defer adapter.CleanUp()
server := http.Server{
Addr: ":8080",
Handler: createRouter(adapter),
}
fmt.Println("Server is running on port 8080")
server.ListenAndServe()
}