Skip to content

Commit

Permalink
修改路由
Browse files Browse the repository at this point in the history
  • Loading branch information
ErwinDarg committed Feb 10, 2020
1 parent 065c738 commit d47b278
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 21 deletions.
14 changes: 14 additions & 0 deletions cloud/src/rasp-cloud/controllers/general.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package controllers

import "rasp-cloud/environment"

type GeneralController struct {
BaseController
}

// @router /version [post]
func (o *GeneralController) Version() {
result := make(map[string]interface{})
result["version"] = environment.Version
o.Serve(result)
}
8 changes: 0 additions & 8 deletions cloud/src/rasp-cloud/controllers/iast/iast.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"github.com/gorilla/websocket"
"net/http"
"rasp-cloud/controllers"
"rasp-cloud/environment"
"rasp-cloud/models"
"strings"
"sync"
Expand Down Expand Up @@ -195,13 +194,6 @@ func (o *WebsocketController) Get() {

}

// @router /version [post]
func (o *IastController) Version() {
result := make(map[string]interface{})
result["version"] = environment.Version
o.Serve(result)
}

// @router /auth [post]
func (o *IastController) Auth() {
o.ServeWithEmptyData()
Expand Down
11 changes: 7 additions & 4 deletions cloud/src/rasp-cloud/environment/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,18 +295,21 @@ func fork() (err error) {

func initLogger() {
logPath := "logs/api"
maxSize := strconv.FormatInt(conf.AppConfig.LogMaxSize, 10)
maxDays := strconv.Itoa(conf.AppConfig.LogMaxDays)
maxSize := strconv.FormatInt(beego.AppConfig.DefaultInt64("LogMaxSize", 104857600), 10)
maxDays := strconv.Itoa(beego.AppConfig.DefaultInt("LogMaxDays", 10))
if isExists, _ := tools.PathExists(logPath); !isExists {
err := os.MkdirAll(logPath, os.ModePerm)
if err != nil {
tools.Panic(tools.ErrCodeLogInitFailed, "failed to create logs/api dir", err)
}
}
logs.SetLogFuncCall(true)
logs.SetLogger(logs.AdapterFile,
err := logs.SetLogger(logs.AdapterFile,
`{"filename":"`+logPath+`/agent-cloud.log","daily":true,"maxdays":`+maxDays+`,"perm":"0777","maxsize": `+maxSize+`}`)

if err != nil {
beego.Error(err)
os.Exit(-1)
}
}

func initEnvConf() {
Expand Down
8 changes: 8 additions & 0 deletions cloud/src/rasp-cloud/routers/commentsRouter_controllers.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,12 @@ func init() {
Filters: nil,
Params: nil})

beego.GlobalControllerRouter["rasp-cloud/controllers:GeneralController"] = append(beego.GlobalControllerRouter["rasp-cloud/controllers:GeneralController"],
beego.ControllerComments{
Method: "Version",
Router: `/`,
AllowHTTPMethods: []string{"post"},
MethodParams: param.Make(),
Filters: nil,
Params: nil})
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,6 @@ func init() {
Filters: nil,
Params: nil})

beego.GlobalControllerRouter["rasp-cloud/controllers/iast:IastController"] = append(beego.GlobalControllerRouter["rasp-cloud/controllers/iast:IastController"],
beego.ControllerComments{
Method: "Version",
Router: `/version`,
AllowHTTPMethods: []string{"post"},
MethodParams: param.Make(),
Filters: nil,
Params: nil})

beego.GlobalControllerRouter["rasp-cloud/controllers/iast:IastController"] = append(beego.GlobalControllerRouter["rasp-cloud/controllers/iast:IastController"],
beego.ControllerComments{
Method: "Auth",
Expand Down
2 changes: 2 additions & 0 deletions cloud/src/rasp-cloud/routers/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,10 @@ func InitRouter() {
)
userNS := beego.NewNamespace("/user", beego.NSInclude(&api.UserController{}))
pingNS := beego.NewNamespace("/ping", beego.NSInclude(&controllers.PingController{}))
versionNS := beego.NewNamespace("/version", beego.NSInclude(&controllers.GeneralController{}))
ns := beego.NewNamespace("/v1")
ns.Namespace(pingNS)
ns.Namespace(versionNS)
startType := *conf.AppConfig.Flag.StartType
if startType == conf.StartTypeForeground {
ns.Namespace(foregroudNS, agentNS, userNS, iastNS)
Expand Down

0 comments on commit d47b278

Please sign in to comment.