[frontend-gray] support grayKey from localStorage (#1395)

This commit is contained in:
mamba
2024-10-18 13:58:52 +08:00
committed by GitHub
parent c67f494b49
commit 11ff2d1d31
6 changed files with 115 additions and 43 deletions

View File

@@ -49,17 +49,18 @@ type BodyInjection struct {
}
type GrayConfig struct {
UserStickyMaxAge string
TotalGrayWeight int
GrayKey string
GraySubKey string
Rules []*GrayRule
Rewrite *Rewrite
Html string
BaseDeployment *Deployment
GrayDeployments []*Deployment
BackendGrayTag string
Injection *Injection
UserStickyMaxAge string
TotalGrayWeight int
GrayKey string
LocalStorageGrayKey string
GraySubKey string
Rules []*GrayRule
Rewrite *Rewrite
Html string
BaseDeployment *Deployment
GrayDeployments []*Deployment
BackendGrayTag string
Injection *Injection
}
func convertToStringList(results []gjson.Result) []string {
@@ -81,7 +82,11 @@ func convertToStringMap(result gjson.Result) map[string]string {
func JsonToGrayConfig(json gjson.Result, grayConfig *GrayConfig) {
// 解析 GrayKey
grayConfig.LocalStorageGrayKey = json.Get("localStorageGrayKey").String()
grayConfig.GrayKey = json.Get("grayKey").String()
if grayConfig.LocalStorageGrayKey != "" {
grayConfig.GrayKey = grayConfig.LocalStorageGrayKey
}
grayConfig.GraySubKey = json.Get("graySubKey").String()
grayConfig.BackendGrayTag = json.Get("backendGrayTag").String()
grayConfig.UserStickyMaxAge = json.Get("userStickyMaxAge").String()