-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
51 lines (41 loc) · 1.56 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
package main
import (
"net/http"
"github.com/gin-gonic/gin"
"github.com/rizqyfahmi/gin-greetings-clean-architecture/config"
"github.com/rizqyfahmi/gin-greetings-clean-architecture/constant"
"github.com/rizqyfahmi/gin-greetings-clean-architecture/routes"
"github.com/sirupsen/logrus"
middlewares "github.com/rizqyfahmi/gin-greetings-clean-architecture/middlewares/timeout_limitter"
CustomErrorPackage "github.com/rizqyfahmi/gin-greetings-clean-architecture/pkg/custom_error"
LoggerPackage "github.com/rizqyfahmi/gin-greetings-clean-architecture/pkg/logger"
)
func main() {
path := "main"
LoggerPackage.NewLogger()
config := config.NewConfig()
err := config.Setup()
if err != nil {
err = err.(*CustomErrorPackage.CustomError).UnshiftPath(path)
LoggerPackage.WriteLog(logrus.Fields{
"path": err.(*CustomErrorPackage.CustomError).GetPath(),
"title": err.(*CustomErrorPackage.CustomError).GetDisplay().Error(),
}).Panic(err.(*CustomErrorPackage.CustomError).GetPlain())
}
timeoutLimiter := middlewares.NewTimeoutLimiter(config.GetConfig())
port := config.GetConfig().App.Port
engine := gin.New()
routes := routes.NewRoutes(engine, timeoutLimiter)
routes.Index()
if err := http.ListenAndServe(":"+port, routes.GetEngine()); err != nil {
err = CustomErrorPackage.NewCustomError(
constant.ErrServe,
err,
path,
)
LoggerPackage.WriteLog(logrus.Fields{
"path": err.(*CustomErrorPackage.CustomError).GetPath(),
"title": err.(*CustomErrorPackage.CustomError).GetDisplay().Error(),
}).Fatal(err.(*CustomErrorPackage.CustomError).GetPlain())
}
}