反向代理源站实现使用域名分组

This commit is contained in:
刘祥超
2021-09-20 11:54:45 +08:00
parent f1af151080
commit 7a1bd29f6f
4 changed files with 49 additions and 11 deletions

View File

@@ -3,10 +3,11 @@ package models
import (
"encoding/json"
"errors"
"github.com/TeaOSLab/EdgeAPI/internal/remotelogs"
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
)
// 解析地址
// DecodeAddr 解析地址
func (this *Origin) DecodeAddr() (*serverconfigs.NetworkAddressConfig, error) {
if len(this.Addr) == 0 || this.Addr == "null" {
return nil, errors.New("addr is empty")
@@ -15,3 +16,14 @@ func (this *Origin) DecodeAddr() (*serverconfigs.NetworkAddressConfig, error) {
err := json.Unmarshal([]byte(this.Addr), addr)
return addr, err
}
func (this *Origin) DecodeDomains() []string {
var result = []string{}
if len(this.Domains) > 0 {
err := json.Unmarshal([]byte(this.Domains), &result)
if err != nil {
remotelogs.Error("Origin.DecodeDomains", err.Error())
}
}
return result
}