-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
31 lines (26 loc) · 719 Bytes
/
main.go
File metadata and controls
31 lines (26 loc) · 719 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
31
package main
import (
"fmt"
"github.com/gin-gonic/gin"
"restApi/constants"
"restApi/routes"
)
var users []constants.User
var host = "localhost:8080"
func main() {
router := gin.Default()
if err := router.SetTrustedProxies([]string{"127.0.0.1", "192.168.3.6"}); err != nil {
fmt.Println(err)
return
}
router.GET("/users", routes.GetUser(&users))
router.GET("/users/:id", routes.GetUserById(&users))
router.POST("/users", routes.AppendUser(&users))
router.DELETE("/users/:id", routes.DeleteUser(&users))
router.PATCH("/users/:id", routes.ModifyUser(&users))
if err := router.Run(host); err != nil {
fmt.Println(err)
return
}
fmt.Printf("Server running at %s\nPress Ctrl-C to exit...", host)
}