-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
71 lines (61 loc) · 1.51 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package main
import (
"net/http"
"nnz/service"
"os"
"github.com/gin-gonic/gin"
//"github.com/penndev/rtmp-go/rtmp"
)
func main() {
g := gin.Default()
//gin.SetMode(gin.DebugMode)
g.Use(CrosHandler())
args := os.Args
if len(args) == 1 {
args = append(args, ".")
}
loadRoute(g, args[1])
g.Run(":2000")
//rtmp.NewRtmp()
}
// 加载路由
func loadRoute(g *gin.Engine, root string) {
if root == "" {
root = "."
}
g.StaticFS("/static", http.Dir(root+"/static"))
g.StaticFile("/", root+"/static/index.html")
g.StaticFile("/js", root+"/static/ncm.js")
g.StaticFile("/js_v2", root+"/static/ncm_v2.js")
// 网易云端的ws
g.GET("/ncm", service.NCM_WebSocket)
// 副屏端的ws(已弃用)(又启用了)
g.GET("/cli", service.CLI_WebSocket)
// 获取信息
g.GET("/s", service.CLI_S)
// 切歌
g.GET("/prev", service.CLI_PREV)
g.GET("/next", service.CLI_NEXT)
// 暂停
g.GET("/play", service.CLI_PLAY)
// 喜欢
g.GET("/like", service.CLI_LIKE)
// 前进
g.GET("/less", service.CLI_LESS)
g.GET("/more", service.CLI_MORE)
// 搜索切歌
g.GET("/search", service.CLI_SEARCH)
// 更改播放顺序
g.GET("/order", service.CLI_ORDER)
// 副屏端上传图片
g.POST("/picture", service.MORE_PICTURE)
}
func CrosHandler() gin.HandlerFunc {
return func(context *gin.Context) {
context.Header("Access-Control-Allow-Origin", "*") // 设置允许访问所有域
context.Header("Access-Control-Max-Age", "172800")
context.Header("Cache-Control", "no-store")
//处理请求
context.Next()
}
}