-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathserver.go
38 lines (27 loc) · 853 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
package main
import (
"github.com/HanFa/learn-go/gin-example/controllers"
"github.com/HanFa/learn-go/gin-example/middlewares"
"github.com/gin-gonic/gin"
"log"
)
func main() {
server := gin.Default()
server.GET("/ping", func(context *gin.Context) {
context.String(200, "%s", "pong")
})
server.Static("/resources", "./resources")
server.StaticFile("/mycoolvideo", "./resources/海豹.mp4")
videoController := controllers.NewVideoController()
videoGroup := server.Group("/videos")
videoGroup.Use(middlewares.MyLogger())
// GET /videos
videoGroup.GET("/", videoController.GetAll)
// PUT /videos/123
videoGroup.PUT("/:id", videoController.Update)
// POST /videos
videoGroup.POST("/", videoController.Create)
// DELETE /videos/123
videoGroup.DELETE("/:id", videoController.Delete)
log.Fatalln(server.Run("localhost:8080"))
}