-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
30 lines (22 loc) · 895 Bytes
/
Copy pathmain.go
File metadata and controls
30 lines (22 loc) · 895 Bytes
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
package main
// main.go : the entry point of the application.
// start server, wire things together
import (
"go-crud/middleware"
"go-crud/routes"
"github.com/gin-gonic/gin"
)
func main() {
router := gin.Default() // returns a Engine instance which contains the router
// runs on every request before routes are executed. It is a middleware.
router.Use(middleware.CORS())
// wire all routes to their handlers
// we can directly do
// router.GET("/retrieve", handler.Retrieve)
// but it gets messy fast : and at scale (50 routes), it becomes difficult to maintain
// so we use routes.go to wire all routes to their handlers
// routes.go is a better way to organize routes
routes.Register(router)
router.Run() // listens on 0.0.0.0:8080 by default and serves the application
// Run internally uses ListenAndServe() to start the server on the port specified in the router.
}