/
router.go
52 lines (44 loc) · 1.6 KB
/
router.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 controllers
import (
"github.com/bmbstack/ripple"
"github.com/labstack/echo/v4"
"github.com/labstack/echo/v4/middleware"
"github.com/bmbstack/ripple/cmd/ripple/templates/internal/controllers/v1"
"github.com/bmbstack/ripple/cmd/ripple/templates/internal/ecode"
)
func RouteAPI() {
echoMux := ripple.Default().GetEcho()
echoMux.GET("/", func(ctx echo.Context) error {
result := map[string]interface{}{
"username": "tom",
}
return ecode.OK(ctx, result)
})
//===========================================================
// common
//===========================================================
echoMux.Use(middleware.Gzip())
echoMux.Use(middleware.Secure())
allowOriginsValue := []string{"*"}
//allowOriginsValue := []string{"http://www.ripple.com", "http://api.ripple.com"}
echoMux.Use(middleware.CORSWithConfig(middleware.CORSConfig{
AllowOrigins: allowOriginsValue,
AllowHeaders: []string{echo.HeaderOrigin, echo.HeaderContentType, echo.HeaderAuthorization},
AllowMethods: []string{echo.GET, echo.HEAD, echo.PUT, echo.PATCH, echo.POST, echo.DELETE, echo.OPTIONS},
}))
//echoMux.Use(middleware.CSRFWithConfig(middleware.CSRFConfig{
// TokenLength: 32,
// TokenLookup: "header:X-CSRF-TOKEN",
// ContextKey: "csrf",
// CookieName: "_csrf",
// CookieMaxAge: 86400,
//}))
//===========================================================
// v1
//===========================================================
v1Group := echoMux.Group("/v1")
homes := v1.HomeController{}
homes.Register()
citys := v1.CityController{Group: v1Group}
citys.Setup()
}