forked from shenjing023/MyCloudMusic_Server_Go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
router.go
43 lines (37 loc) · 915 Bytes
/
router.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
package main
import (
"MyCloudMusic_Server_Go/mylog"
"github.com/julienschmidt/httprouter"
)
/*
路由注册
*/
type Route struct {
Name string
Method string
Path string
HandlerFunc httprouter.Handle
}
type Routes []Route
func allRoutes() Routes {
routes := Routes{
Route{"Index", "GET", "/", Index},
Route{"Search", "GET", "/search", Search},
Route{"Playlist", "GET", "/playlists", PlayList},
Route{"PlaylistDetail", "GET", "/playlist/detail", PlayListDetail},
Route{"SongUrl", "GET", "/music/url", SongUrl},
Route{"PersonFM", "GET", "/personfm", PersonFM},
}
return routes
}
// 返回一个路由
func NewRouter(routes Routes) *httprouter.Router {
router := httprouter.New()
for _, route := range routes {
var handle httprouter.Handle
handle = route.HandlerFunc
handle = mylog.Log(handle)
router.Handle(route.Method, route.Path, handle)
}
return router
}