实现路径规则部分功能

This commit is contained in:
GoEdgeLab
2020-09-21 19:51:50 +08:00
parent f796a1d4d7
commit c126d06f70
50 changed files with 630 additions and 114 deletions

View File

@@ -0,0 +1,50 @@
package webutils
import (
"encoding/json"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
)
// 根据ServerId查找Web配置
func FindWebConfigWithServerId(parentAction *actionutils.ParentAction, serverId int64) (*serverconfigs.HTTPWebConfig, error) {
resp, err := parentAction.RPC().ServerRPC().FindAndInitServerWebConfig(parentAction.AdminContext(), &pb.FindAndInitServerWebConfigRequest{ServerId: serverId})
if err != nil {
return nil, err
}
config := &serverconfigs.HTTPWebConfig{}
err = json.Unmarshal(resp.WebJSON, config)
if err != nil {
return nil, err
}
return config, nil
}
// 根据LocationId查找Web配置
func FindWebConfigWithLocationId(parentAction *actionutils.ParentAction, locationId int64) (*serverconfigs.HTTPWebConfig, error) {
resp, err := parentAction.RPC().HTTPLocationRPC().FindAndInitHTTPLocationWebConfig(parentAction.AdminContext(), &pb.FindAndInitHTTPLocationWebConfigRequest{LocationId: locationId})
if err != nil {
return nil, err
}
config := &serverconfigs.HTTPWebConfig{}
err = json.Unmarshal(resp.WebJSON, config)
if err != nil {
return nil, err
}
return config, nil
}
// 根据WebId查找Web配置
func FindWebConfigWithId(parentAction *actionutils.ParentAction, webId int64) (*serverconfigs.HTTPWebConfig, error) {
resp, err := parentAction.RPC().HTTPWebRPC().FindEnabledHTTPWebConfig(parentAction.AdminContext(), &pb.FindEnabledHTTPWebConfigRequest{WebId: webId})
if err != nil {
return nil, err
}
config := &serverconfigs.HTTPWebConfig{}
err = json.Unmarshal(resp.WebJSON, config)
if err != nil {
return nil, err
}
return config, nil
}