-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
47 lines (37 loc) · 1 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
package main
import (
"ahmaruff/wschat/user"
"ahmaruff/wschat/wsservice"
"os"
"github.com/labstack/echo/v4"
"github.com/labstack/echo/v4/middleware"
"github.com/rs/zerolog"
)
func main() {
// err := godotenv.Load()
// if err != nil {
// log.Fatal().Err(err).Msg(".env file not found")
//}
e := echo.New()
logger := zerolog.New(os.Stdout)
e.Use(middleware.RequestLoggerWithConfig(middleware.RequestLoggerConfig{
LogURI: true,
LogStatus: true,
LogValuesFunc: func(c echo.Context, v middleware.RequestLoggerValues) error {
logger.Info().Str("URI", v.URI).Int("Status", v.Status).Msg("request")
return nil
},
}))
e.Use(middleware.Recover())
e.Use(middleware.CORSWithConfig(middleware.CORSConfig{
AllowOrigins: []string{"*"},
AllowHeaders: []string{echo.HeaderOrigin, echo.HeaderContentType, echo.HeaderAccept},
}))
user.InitUserRoutes(e)
wsservice.InitWsRoutes(e)
port := os.Getenv("WSCHAT_SERVER_PORT")
if port == "" {
port = "5000"
}
e.Logger.Fatal(e.Start(":" + port))
}