-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
52 lines (44 loc) · 1.08 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
package main
import (
"github.com/insaneadinesia/go-mockemok/config"
"github.com/insaneadinesia/go-mockemok/handler"
"github.com/labstack/echo/v4"
)
func main() {
// load config
e := echo.New()
conf := config.Load()
for _, mock := range conf.Mock {
mock := mock
group := e.Group(mock.Group)
for _, request := range mock.Request {
group.Use(setRequestMiddleware(request))
switch request.Method {
case "GET":
group.GET(request.Path, handler.RequestHandler)
break
case "POST":
group.POST(request.Path, handler.RequestHandler)
break
case "PUT":
group.PUT(request.Path, handler.RequestHandler)
break
case "PATCH":
group.PATCH(request.Path, handler.RequestHandler)
break
case "DELETE":
group.DELETE(request.Path, handler.RequestHandler)
break
}
}
}
e.Logger.Fatal(e.Start(conf.GetPort()))
}
func setRequestMiddleware(request config.MockGroupRequest) echo.MiddlewareFunc {
return func(next echo.HandlerFunc) echo.HandlerFunc {
return func(c echo.Context) error {
c.Set("Request", request)
return next(c)
}
}
}