-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
57 lines (49 loc) · 1.33 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
53
54
55
56
57
package main
import (
"context"
"fmt"
"net/http"
"os"
"os/signal"
"time"
// "wallett/data"
"wallett/infra/persistence/db/sqlite"
"wallett/main/handlers"
"wallett/presentation/helpers"
"github.com/labstack/echo"
"github.com/labstack/echo/middleware"
)
func main() {
// data := data.NewWSD("wsd.dat")
sqlite.Connect("gorm.db")
e := echo.New()
e.Validator = helpers.NewCustomValidator()
e.Use(middleware.LoggerWithConfig(middleware.LoggerConfig{
Format: "method=${method}, uri=${uri}, status=${status}\n",
}))
e.Use(middleware.RecoverWithConfig(middleware.RecoverConfig{
DisablePrintStack: true,
}))
e.HTTPErrorHandler = func(err error, c echo.Context) {
fmt.Println(c.Path(), c.QueryParams(), err)
e.DefaultHTTPErrorHandler(err, c)
}
api := e.Group("/api/v1")
userHandlers := handlers.NewUserHandlers(sqlite.GetDB())
userHandlers.SetupRoutes(api)
walletHandlers := handlers.NewWalletHandlers(sqlite.GetDB())
walletHandlers.SetupHandlers(api)
go func() {
if err := e.Start(":3333"); err != nil && err != http.ErrServerClosed {
e.Logger.Fatal("shutting down the server")
}
}()
quit := make(chan os.Signal, 1)
signal.Notify(quit, os.Interrupt)
<-quit
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
if err := e.Shutdown(ctx); err != nil {
e.Logger.Fatal(err)
}
}