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
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
5 deletions
+11
-5
relay/common/override.go
+11
-5
No files found.
relay/common/override.go
View file @
7323dcf9
...
...
@@ -9,11 +9,11 @@ import (
)
type
ConditionOperation
struct
{
Path
string
`json:"path"`
// JSON路径
Mode
string
`json:"mode"`
// full, prefix, suffix, contains, gt, gte, lt, lte
Value
interface
{}
`json:"value"`
// 匹配的值
Invert
bool
`json:"invert"`
// 反选功能,true表示取反结果
Path
string
`json:"path"`
// JSON路径
Mode
string
`json:"mode"`
// full, prefix, suffix, contains, gt, gte, lt, lte
Value
interface
{}
`json:"value"`
// 匹配的值
Invert
bool
`json:"invert"`
// 反选功能,true表示取反结果
PassMissingKey
bool
`json:"pass_missing_key"`
// 未获取到json key时的行为
}
type
ParamOperation
struct
{
...
...
@@ -99,6 +99,9 @@ func tryParseOperations(paramOverride map[string]interface{}) ([]ParamOperation,
if
invert
,
ok
:=
condMap
[
"invert"
]
.
(
bool
);
ok
{
condition
.
Invert
=
invert
}
if
passMissingKey
,
ok
:=
condMap
[
"pass_missing_key"
]
.
(
bool
);
ok
{
condition
.
PassMissingKey
=
passMissingKey
}
operation
.
Conditions
=
append
(
operation
.
Conditions
,
condition
)
}
}
...
...
@@ -150,6 +153,9 @@ func checkConditions(jsonStr string, conditions []ConditionOperation, logic stri
func
checkSingleCondition
(
jsonStr
string
,
condition
ConditionOperation
)
(
bool
,
error
)
{
value
:=
gjson
.
Get
(
jsonStr
,
condition
.
Path
)
if
!
value
.
Exists
()
{
if
condition
.
PassMissingKey
{
return
true
,
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