-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
53 lines (48 loc) · 1.67 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
package main
import (
"github.com/huzairuje/chatat_backend_engineer/database"
_ "github.com/huzairuje/chatat_backend_engineer/docs/products"
productsDomain "github.com/huzairuje/chatat_backend_engineer/product/routes"
"github.com/huzairuje/chatat_backend_engineer/response"
"github.com/huzairuje/chatat_backend_engineer/util"
"github.com/huzairuje/chatat_backend_engineer/validator"
"github.com/labstack/echo/v4"
"github.com/sirupsen/logrus"
echoSwagger "github.com/swaggo/echo-swagger"
)
// @title Products API
// @version 1.0
// @description This is a products server.
// @description you can access the code on github https://github.com/huzairuje/go-echo-example/
// @termsOfService http://swagger.io/terms/
// @contact.name API Support
// @contact.url http://www.swagger.io/support
// @contact.email [email protected]
// @license.name MIT License
// @license.url https://opensource.org/licenses/MIT
// @schemes http
func main() {
//load config from config.yml
loadCfg := util.LoadConfig()
//initiate database connection
db := database.CreateDB(loadCfg)
//initiate echo App instance
router := echo.New()
//initiate validator
router.Validator = validator.NewValidator()
//custom response for not matching routes
echo.NotFoundHandler = func(c echo.Context) error {
// render 404 custom response
return response.NotFound(c, "Not Matching of Any Routes", nil, "Not Found")
}
//initiate routes by domain (this domain just products domain)
productsDomain.ProductRoutes(router, db)
//initiate swagger routes
router.GET("/swagger/*", echoSwagger.WrapHandler)
//start web (echo) service
err := router.Start(loadCfg.ServerPort)
if err != nil {
logrus.Info(err)
panic(err)
}
}