-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.go
41 lines (32 loc) · 842 Bytes
/
server.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
package main
import (
"os"
"github.com/arias9306/golang-api-test/controllers"
"github.com/arias9306/golang-api-test/services"
"github.com/gin-gonic/gin"
_ "github.com/heroku/x/hmetrics/onload"
)
var (
movieService services.MoviesService = services.New()
movieController controllers.MoviesController = controllers.New(movieService)
)
func main() {
server := gin.Default()
server.GET("/echo", func(c *gin.Context) {
c.JSON(200, gin.H{
"message": "Up and Running",
})
})
movies := server.Group("/movies")
{
movies.GET("", movieController.GetAll)
movies.GET("/:id", movieController.GetByID)
movies.PUT("/:id/rating", movieController.UpdateMovieRating)
movies.PUT("/:id/genre", movieController.UpdateMovieGenre)
}
port := os.Getenv("PORT")
if port == "" {
port = "3000"
}
server.Run(":"+port)
}