router.go 2.6 KB
package routers

import (
	"github.com/astaxie/beego"
	"github.com/prometheus/client_golang/prometheus/promhttp"
	"net/http"
	"opp/controllers"
	"opp/controllers/v1"
	"opp/services/websocket"
)

var nsV1 *beego.Namespace

func init() {
	nsV1 := beego.NewNamespace("v1",
		beego.NSNamespace("ucenter", beego.NSInclude(&v1.UcenterController{})),
		beego.NSNamespace("auth", beego.NSBefore(controllers.FilterComm), beego.NSInclude(&v1.AuthController{})),
		beego.NSNamespace("upload", beego.NSBefore(controllers.FilterComm), beego.NSInclude(&v1.UploadController{})),
		beego.NSNamespace("version", beego.NSBefore(controllers.FilterComm), beego.NSInclude(&v1.VersionController{})),
		beego.NSNamespace("commend", beego.NSBefore(controllers.FilterComm), beego.NSInclude(&v1.CommendController{})),
		beego.NSNamespace("user", beego.NSBefore(controllers.FilterComm), beego.NSInclude(&v1.UserController{})),
		beego.NSNamespace("chance", beego.NSBefore(controllers.FilterComm), beego.NSInclude(&v1.ChanceController{})),
		beego.NSNamespace("message", beego.NSBefore(controllers.FilterComm), beego.NSInclude(&v1.MessageController{})),
		beego.NSNamespace("department", beego.NSBefore(controllers.FilterComm), beego.NSInclude(&v1.DepartmentController{})),
		beego.NSNamespace("config", beego.NSBefore(controllers.FilterComm), beego.NSInclude(&v1.ConfigController{})),
		beego.NSNamespace("file", beego.NSBefore(controllers.FilterComm), beego.NSInclude(&v1.FileController{})),
		beego.NSNamespace("achievement", beego.NSBefore(controllers.FilterComm), beego.NSInclude(&v1.AchievementController{})),
		beego.NSNamespace("rank", beego.NSBefore(controllers.FilterComm), beego.NSInclude(&v1.RankController{})),
	)
	beego.AddNamespace(nsV1)

	nsV2 := beego.NewNamespace("v2",
		beego.NSNamespace("user", beego.NSBefore(controllers.FilterComm), beego.NSInclude(&v1.UserController{})),
	)
	beego.AddNamespace(nsV2)

	nsH5 := beego.NewNamespace("h5", beego.NSBefore(controllers.LogRequestData), beego.NSBefore(controllers.AllowOption), beego.NSInclude(&controllers.H5Controller{}))
	nsVod := beego.NewNamespace("vod", beego.NSBefore(controllers.LogRequestData), beego.NSBefore(controllers.AllowOption), beego.NSBefore(controllers.CheckSignMiddleware), beego.NSInclude(&v1.VodController{}))
	beego.AddNamespace(nsH5)
	beego.AddNamespace(nsVod)
	//post 下载文件
	beego.Router("/file/opp/*", &v1.FileController{}, "post:DownLoad")
	//get 直接获取文件
	beego.SetStaticPath("/file/opp", beego.AppConfig.String("source_path"))
	beego.SetStaticPath("/log", beego.AppConfig.String("aliyun_logs_access"))
	beego.Handler("/metrics", promhttp.Handler())
	beego.Handler("/upgrage", http.HandlerFunc(websocket.Upgrage))
}