liuxiaolong
2020-08-12 8849dda9c4fd92467e2c05c15ea483abae6af8e5
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
// @APIVersion 1.0.0
// @Title beego Test API
// @Description beego has a very cool tools to autogenerate documents for your API
// @Contact astaxie@gmail.com
// @TermsOfServiceUrl http://beego.me/
// @License Apache 2.0
// @LicenseUrl http://www.apache.org/licenses/LICENSE-2.0.html
package routers
 
import (
    "car-service/controllers"
    "car-service/extend/util"
    "fmt"
    "github.com/astaxie/beego"
    "github.com/astaxie/beego/plugins/cors"
)
 
func init() {
    //运行跨域请求
    //在http请求的响应流头部加上如下信息
    //rw.Header().Set("Access-Control-Allow-Origin", "*")
    beego.InsertFilter("*", beego.BeforeRouter, cors.Allow(&cors.Options{
        AllowAllOrigins: true,
        AllowMethods: []string{"GET", "POST", "PUT", "DELETE", "OPTIONS"},
        AllowHeaders: []string{"Origin", "Authorization", "Access-Control-Allow-Origin", "Access-Control-Allow-Headers", "Content-Type"},
        ExposeHeaders: []string{"Content-Length", "Access-Control-Allow-Origin", "Access-Control-Allow-Headers", "Content-Type"},
        AllowCredentials: true,
    }))
    //ns := beego.NewNamespace("/v1",
    //    beego.NSNamespace("/user",
    //        beego.NSInclude(
    //            &controllers.UserController{},
    //        ),
    //    ),
    //    beego.NSNamespace("/car",
    //        beego.NSInclude(
    //            &controllers.CarController{},
    //        ),
    //    ),
    //)
    //beego.AddNamespace(ns)
    //beego.Router("/basic/api/car/app/user", &controllers.UserController{})
    rootPath := util.GetAppRootPath()
    fmt.Println("rootPath:", rootPath)
    beego.SetStaticPath("/download", rootPath+"/download")
    preApi := "/basic/api"
    beego.Router(preApi+"/car/statistic", &controllers.CarController{}, "*:Statistic")
    beego.Router(preApi+"/car/spaceNo", &controllers.CarController{}, "*:SpaceNo")
    beego.Router(preApi+"/car/app/version", &controllers.AppController{}, "*:Version")
    beego.Router(preApi+"/car/restriction", &controllers.RestrictionController{}, "*:Restriction")
    beego.Router(preApi+"/code/new", &controllers.CodeController{}, "*:New")
    beego.Router(preApi+"/user/login", &controllers.UserController{}, "*:Login")
    beego.Router(preApi+"/user/logout", &controllers.UserController{}, "*:Logout")
    beego.Router(preApi+"/user/addPlateNo", &controllers.UserController{}, "*:AddPlateNo")
    beego.Router(preApi+"/user/myPlateNos", &controllers.UserController{}, "*:MyPlateNos")
    beego.Router(preApi+"/user/delPlateNo", &controllers.UserController{}, "*:DelPlateNo")
 
    beego.Router(preApi+"/user/all", &controllers.UserController{}, "*:GetUserAll")
    beego.Router(preApi+"/user/sync", &controllers.UserController{}, "*:Sync")
 
    beego.Router(preApi+"/car/crossRecord", &controllers.CarController{}, "*:CrossRecord")
    beego.Router(preApi+"/car/testPush", &controllers.CarController{}, "*:TestPush")
}