mirror of
https://github.com/TeaOSLab/EdgeAdmin.git
synced 2025-11-07 23:30:26 +08:00
路由规则找不到的时候提示用户
This commit is contained in:
@@ -3,6 +3,7 @@
|
|||||||
package utils
|
package utils
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"reflect"
|
"reflect"
|
||||||
)
|
)
|
||||||
@@ -22,3 +23,8 @@ func JSONClone(v interface{}) (interface{}, error) {
|
|||||||
|
|
||||||
return nv, nil
|
return nv, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 判断JSON数据是否为null
|
||||||
|
func JSONIsNull(jsonData []byte) bool {
|
||||||
|
return len(jsonData) == 0 || bytes.Equal(jsonData, []byte("null"))
|
||||||
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ package utils_test
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/TeaOSLab/EdgeAdmin/internal/utils"
|
"github.com/TeaOSLab/EdgeAdmin/internal/utils"
|
||||||
|
"github.com/iwind/TeaGo/assert"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -23,3 +24,12 @@ func TestJSONClone(t *testing.T) {
|
|||||||
t.Logf("%p, %#v", c, c)
|
t.Logf("%p, %#v", c, c)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
func TestJSONIsNull(t *testing.T) {
|
||||||
|
var a = assert.NewAssertion(t)
|
||||||
|
a.IsTrue(utils.JSONIsNull(nil))
|
||||||
|
a.IsTrue(utils.JSONIsNull([]byte{}))
|
||||||
|
a.IsTrue(utils.JSONIsNull([]byte("null")))
|
||||||
|
a.IsFalse(utils.JSONIsNull([]byte{1, 2, 3}))
|
||||||
|
}
|
||||||
@@ -28,7 +28,7 @@ func (this *IndexAction) RunGet(params struct {
|
|||||||
}
|
}
|
||||||
this.Data["webId"] = webConfig.Id
|
this.Data["webId"] = webConfig.Id
|
||||||
|
|
||||||
locationMaps := []maps.Map{}
|
var locationMaps = []maps.Map{}
|
||||||
if webConfig.Locations != nil {
|
if webConfig.Locations != nil {
|
||||||
for _, location := range webConfig.Locations {
|
for _, location := range webConfig.Locations {
|
||||||
err := location.ExtractPattern()
|
err := location.ExtractPattern()
|
||||||
@@ -46,7 +46,7 @@ func (this *IndexAction) RunGet(params struct {
|
|||||||
this.ErrorPage(err)
|
this.ErrorPage(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
pieces := strings.Split(location.Pattern, " ")
|
var pieces = strings.Split(location.Pattern, " ")
|
||||||
if len(pieces) == 2 {
|
if len(pieces) == 2 {
|
||||||
m["pattern"] = pieces[1]
|
m["pattern"] = pieces[1]
|
||||||
m["patternTypeName"] = serverconfigs.FindLocationPatternTypeName(location.PatternType())
|
m["patternTypeName"] = serverconfigs.FindLocationPatternTypeName(location.PatternType())
|
||||||
|
|||||||
@@ -23,7 +23,12 @@ func (this *IndexAction) Init() {
|
|||||||
func (this *IndexAction) RunGet(params struct {
|
func (this *IndexAction) RunGet(params struct {
|
||||||
LocationId int64
|
LocationId int64
|
||||||
}) {
|
}) {
|
||||||
locationConfig := this.Data.Get("locationConfig").(*serverconfigs.HTTPLocationConfig)
|
var location = this.Data.Get("locationConfig")
|
||||||
|
if location == nil {
|
||||||
|
this.NotFound("location", params.LocationId)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
var locationConfig = location.(*serverconfigs.HTTPLocationConfig)
|
||||||
|
|
||||||
this.Data["patternTypes"] = serverconfigs.AllLocationPatternTypes()
|
this.Data["patternTypes"] = serverconfigs.AllLocationPatternTypes()
|
||||||
|
|
||||||
|
|||||||
@@ -20,13 +20,13 @@ func NewLocationHelper() *LocationHelper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (this *LocationHelper) BeforeAction(actionPtr actions.ActionWrapper) {
|
func (this *LocationHelper) BeforeAction(actionPtr actions.ActionWrapper) {
|
||||||
action := actionPtr.Object()
|
var action = actionPtr.Object()
|
||||||
if action.Request.Method != http.MethodGet {
|
if action.Request.Method != http.MethodGet {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
serverIdString := action.ParamString("serverId")
|
var serverIdString = action.ParamString("serverId")
|
||||||
locationIdString := action.ParamString("locationId")
|
var locationIdString = action.ParamString("locationId")
|
||||||
|
|
||||||
action.Data["leftMenuItemIsDisabled"] = true
|
action.Data["leftMenuItemIsDisabled"] = true
|
||||||
action.Data["mainMenu"] = "server"
|
action.Data["mainMenu"] = "server"
|
||||||
@@ -39,7 +39,7 @@ func (this *LocationHelper) BeforeAction(actionPtr actions.ActionWrapper) {
|
|||||||
if parentActionValue.IsValid() {
|
if parentActionValue.IsValid() {
|
||||||
parentAction, isOk := parentActionValue.Interface().(actionutils.ParentAction)
|
parentAction, isOk := parentActionValue.Interface().(actionutils.ParentAction)
|
||||||
if isOk {
|
if isOk {
|
||||||
locationId := action.ParamInt64("locationId")
|
var locationId = action.ParamInt64("locationId")
|
||||||
locationConfig, isOk := FindLocationConfig(&parentAction, locationId)
|
locationConfig, isOk := FindLocationConfig(&parentAction, locationId)
|
||||||
if !isOk {
|
if !isOk {
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -2,9 +2,12 @@ package locationutils
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
|
"github.com/TeaOSLab/EdgeAdmin/internal/utils"
|
||||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||||
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
|
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
|
||||||
|
"github.com/iwind/TeaGo/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
// FindLocationConfig 查找路由规则配置
|
// FindLocationConfig 查找路由规则配置
|
||||||
@@ -15,6 +18,11 @@ func FindLocationConfig(parentAction *actionutils.ParentAction, locationId int64
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if utils.JSONIsNull(locationConfigResp.LocationJSON) {
|
||||||
|
parentAction.ErrorPage(errors.New("location '" + types.String(locationId) + "' not found"))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
locationConfig = &serverconfigs.HTTPLocationConfig{}
|
locationConfig = &serverconfigs.HTTPLocationConfig{}
|
||||||
err = json.Unmarshal(locationConfigResp.LocationJSON, locationConfig)
|
err = json.Unmarshal(locationConfigResp.LocationJSON, locationConfig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user