🐛 Fix compare perm node function
This commit is contained in:
parent
0f2b45352c
commit
476ef57236
6
.idea/workspace.xml
generated
6
.idea/workspace.xml
generated
@ -4,7 +4,7 @@
|
||||
<option name="autoReloadType" value="ALL" />
|
||||
</component>
|
||||
<component name="ChangeListManager">
|
||||
<list default="true" id="3fefb2c4-b6f9-466b-a523-53352e8d6f95" name="更改" comment=":bug: Fix query issue">
|
||||
<list default="true" id="3fefb2c4-b6f9-466b-a523-53352e8d6f95" name="更改" comment=":bug: Fix compare perm node panic">
|
||||
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/pkg/internal/services/perms.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/internal/services/perms.go" afterDir="false" />
|
||||
</list>
|
||||
@ -153,7 +153,6 @@
|
||||
</option>
|
||||
</component>
|
||||
<component name="VcsManagerConfiguration">
|
||||
<MESSAGE value=":rotating_light: Fix ts lint issue" />
|
||||
<MESSAGE value=":poop: Remove mis-imported cgo" />
|
||||
<MESSAGE value=":bug: Bug fixes" />
|
||||
<MESSAGE value=":bug: Fix oauth ticket need mfa" />
|
||||
@ -178,7 +177,8 @@
|
||||
<MESSAGE value=":sparkles: Return affiliated to and automated by in userinfo grpc call" />
|
||||
<MESSAGE value=":sparkles: Pagination bots api" />
|
||||
<MESSAGE value=":bug: Fix query issue" />
|
||||
<option name="LAST_COMMIT_MESSAGE" value=":bug: Fix query issue" />
|
||||
<MESSAGE value=":bug: Fix compare perm node panic" />
|
||||
<option name="LAST_COMMIT_MESSAGE" value=":bug: Fix compare perm node panic" />
|
||||
</component>
|
||||
<component name="VgoProject">
|
||||
<settings-migrated>true</settings-migrated>
|
||||
|
@ -22,18 +22,28 @@ func HasPermNodeWithDefault(perms map[string]any, requiredKey string, requiredVa
|
||||
}
|
||||
|
||||
func ComparePermNode(held any, required any) bool {
|
||||
isNumeric := func(val reflect.Value) bool {
|
||||
kind := val.Kind()
|
||||
return kind >= reflect.Int && kind <= reflect.Uint64 || kind >= reflect.Float32 && kind <= reflect.Float64
|
||||
}
|
||||
|
||||
toFloat64 := func(val reflect.Value) float64 {
|
||||
switch val.Kind() {
|
||||
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
|
||||
return float64(val.Int())
|
||||
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
|
||||
return float64(val.Uint())
|
||||
case reflect.Float32, reflect.Float64:
|
||||
return val.Float()
|
||||
default:
|
||||
panic(fmt.Sprintf("non-numeric value of kind %s", val.Kind()))
|
||||
}
|
||||
}
|
||||
|
||||
heldValue := reflect.ValueOf(held)
|
||||
requiredValue := reflect.ValueOf(required)
|
||||
|
||||
switch heldValue.Kind() {
|
||||
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
|
||||
if heldValue.Int() >= requiredValue.Int() {
|
||||
return true
|
||||
}
|
||||
case reflect.Float32, reflect.Float64:
|
||||
if heldValue.Float() >= requiredValue.Float() {
|
||||
return true
|
||||
}
|
||||
case reflect.String:
|
||||
if heldValue.String() == requiredValue.String() {
|
||||
return true
|
||||
@ -45,6 +55,10 @@ func ComparePermNode(held any, required any) bool {
|
||||
}
|
||||
}
|
||||
default:
|
||||
if isNumeric(heldValue) && isNumeric(requiredValue) {
|
||||
return toFloat64(heldValue) >= toFloat64(requiredValue)
|
||||
}
|
||||
|
||||
if reflect.DeepEqual(held, required) {
|
||||
return true
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user