Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
phsl
/
new-api
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
7323dcf9
authored
Aug 16, 2025
by
Nekohy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feats:custom the key missing condition
parent
5683f4b9
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
7 additions
and
1 deletions
+7
-1
relay/common/override.go
+7
-1
No files found.
relay/common/override.go
View file @
7323dcf9
...
@@ -13,7 +13,7 @@ type ConditionOperation struct {
...
@@ -13,7 +13,7 @@ type ConditionOperation struct {
Mode
string
`json:"mode"`
// full, prefix, suffix, contains, gt, gte, lt, lte
Mode
string
`json:"mode"`
// full, prefix, suffix, contains, gt, gte, lt, lte
Value
interface
{}
`json:"value"`
// 匹配的值
Value
interface
{}
`json:"value"`
// 匹配的值
Invert
bool
`json:"invert"`
// 反选功能,true表示取反结果
Invert
bool
`json:"invert"`
// 反选功能,true表示取反结果
PassMissingKey
bool
`json:"pass_missing_key"`
// 未获取到json key时的行为
}
}
type
ParamOperation
struct
{
type
ParamOperation
struct
{
...
@@ -99,6 +99,9 @@ func tryParseOperations(paramOverride map[string]interface{}) ([]ParamOperation,
...
@@ -99,6 +99,9 @@ func tryParseOperations(paramOverride map[string]interface{}) ([]ParamOperation,
if
invert
,
ok
:=
condMap
[
"invert"
]
.
(
bool
);
ok
{
if
invert
,
ok
:=
condMap
[
"invert"
]
.
(
bool
);
ok
{
condition
.
Invert
=
invert
condition
.
Invert
=
invert
}
}
if
passMissingKey
,
ok
:=
condMap
[
"pass_missing_key"
]
.
(
bool
);
ok
{
condition
.
PassMissingKey
=
passMissingKey
}
operation
.
Conditions
=
append
(
operation
.
Conditions
,
condition
)
operation
.
Conditions
=
append
(
operation
.
Conditions
,
condition
)
}
}
}
}
...
@@ -150,6 +153,9 @@ func checkConditions(jsonStr string, conditions []ConditionOperation, logic stri
...
@@ -150,6 +153,9 @@ func checkConditions(jsonStr string, conditions []ConditionOperation, logic stri
func
checkSingleCondition
(
jsonStr
string
,
condition
ConditionOperation
)
(
bool
,
error
)
{
func
checkSingleCondition
(
jsonStr
string
,
condition
ConditionOperation
)
(
bool
,
error
)
{
value
:=
gjson
.
Get
(
jsonStr
,
condition
.
Path
)
value
:=
gjson
.
Get
(
jsonStr
,
condition
.
Path
)
if
!
value
.
Exists
()
{
if
!
value
.
Exists
()
{
if
condition
.
PassMissingKey
{
return
true
,
nil
}
return
false
,
nil
return
false
,
nil
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment