-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.go
62 lines (45 loc) · 1.43 KB
/
server.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
package main
import (
"os"
handlers "github.com/lowsideio/core/handlers"
utils "github.com/lowsideio/core/utils"
"net/http"
"github.com/labstack/echo"
"github.com/labstack/echo/middleware"
)
func init() {
utils.Init()
utils.InitSearch()
}
func main() {
e := echo.New()
e.Debug = true
// Middleware
e.Use(middleware.Logger())
e.Use(middleware.Recover())
e.Use(middleware.CORSWithConfig(middleware.CORSConfig{
AllowOrigins: []string{os.Getenv("CORS_URL")},
AllowMethods: []string{echo.GET, echo.PUT, echo.POST, echo.DELETE, echo.OPTIONS},
}))
e.Use(func(h echo.HandlerFunc) echo.HandlerFunc {
return func(c echo.Context) error {
cc := &utils.RequestContext{c}
return h(cc)
}
})
e.GET("/", func(c echo.Context) error {
return c.String(http.StatusOK, "Hello, World!")
})
e.GET("/motorcycles/slug/:slug", handlers.GetMotorcycleByslug)
e.GET("/motorcycles-specs/:id", handlers.GetMotorcycleSpecsByModelId)
e.GET("/motorcycles/:id", handlers.GetMotorcycle)
e.PUT("/motorcycles/:id", handlers.PutMotorcycle)
e.DELETE("/motorcycles/:id", handlers.DeleteMotorcycle)
e.OPTIONS("/motorcycles/:id", handlers.MotorcyclesOptions)
// e.GET("/motorcycles", handlers.GetMotorcycles)
e.POST("/motorcycles", handlers.PostMotorcycles)
e.OPTIONS("/motorcycles", handlers.MotorcyclesOptions)
e.GET("/search/:text", handlers.GetSearch)
e.GET("/search-algolia/:text", handlers.GetSearchAlgolia)
e.Logger.Fatal(e.Start(":1323"))
}