-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
43 lines (34 loc) · 954 Bytes
/
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
package main
import (
"log"
"net/http"
"github.com/jub0bs/cors"
"github.com/labstack/echo/v4"
)
func main() {
e := echo.New()
e.GET("/hello", handleHello) // note: not configured for CORS
// create CORS middleware
corsMw, err := cors.NewMiddleware(cors.Config{
Origins: []string{"https://example.com"},
Methods: []string{http.MethodGet, http.MethodPost},
RequestHeaders: []string{"Authorization"},
})
if err != nil {
log.Fatal(err)
}
corsMw.SetDebug(true) // turn debug mode on (optional)
api := e.Group("/api", echo.WrapMiddleware(corsMw.Wrap))
api.GET("/users", handleUsersGet)
api.POST("/users", handleUsersPost)
log.Fatal(e.Start(":8080"))
}
func handleHello(c echo.Context) error {
return c.String(http.StatusOK, "Hello, World!")
}
func handleUsersGet(c echo.Context) error {
return nil // omitted implementation
}
func handleUsersPost(c echo.Context) error {
return nil // omitted implementation
}