mirror of
https://github.com/usememos/memos.git
synced 2025-03-04 17:52:18 +08:00
fix: linter warning
This commit is contained in:
parent
2d731c5cc5
commit
58a867e4da
2 changed files with 21 additions and 18 deletions
|
@ -14,8 +14,8 @@ var MemoFilterCELAttributes = []cel.EnvOption{
|
|||
|
||||
// Parse parses the filter string and returns the parsed expression.
|
||||
// The filter string should be a CEL expression.
|
||||
func Parse(filter string) (expr *exprv1.ParsedExpr, err error) {
|
||||
e, err := cel.NewEnv(MemoFilterCELAttributes...)
|
||||
func Parse(filter string, opts ...cel.EnvOption) (expr *exprv1.ParsedExpr, err error) {
|
||||
e, err := cel.NewEnv(opts...)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed to create CEL environment")
|
||||
}
|
||||
|
@ -28,20 +28,23 @@ func Parse(filter string) (expr *exprv1.ParsedExpr, err error) {
|
|||
|
||||
// GetConstValue returns the constant value of the expression.
|
||||
func GetConstValue(expr *exprv1.Expr) (any, error) {
|
||||
switch v := expr.ExprKind.(type) {
|
||||
case *exprv1.Expr_ConstExpr:
|
||||
switch v.ConstExpr.ConstantKind.(type) {
|
||||
case *exprv1.Constant_StringValue:
|
||||
return v.ConstExpr.GetStringValue(), nil
|
||||
case *exprv1.Constant_Int64Value:
|
||||
return v.ConstExpr.GetInt64Value(), nil
|
||||
case *exprv1.Constant_Uint64Value:
|
||||
return v.ConstExpr.GetUint64Value(), nil
|
||||
case *exprv1.Constant_DoubleValue:
|
||||
return v.ConstExpr.GetDoubleValue(), nil
|
||||
case *exprv1.Constant_BoolValue:
|
||||
return v.ConstExpr.GetBoolValue(), nil
|
||||
}
|
||||
v, ok := expr.ExprKind.(*exprv1.Expr_ConstExpr)
|
||||
if !ok {
|
||||
return nil, errors.New("invalid constant expression")
|
||||
}
|
||||
|
||||
switch v.ConstExpr.ConstantKind.(type) {
|
||||
case *exprv1.Constant_StringValue:
|
||||
return v.ConstExpr.GetStringValue(), nil
|
||||
case *exprv1.Constant_Int64Value:
|
||||
return v.ConstExpr.GetInt64Value(), nil
|
||||
case *exprv1.Constant_Uint64Value:
|
||||
return v.ConstExpr.GetUint64Value(), nil
|
||||
case *exprv1.Constant_DoubleValue:
|
||||
return v.ConstExpr.GetDoubleValue(), nil
|
||||
case *exprv1.Constant_BoolValue:
|
||||
return v.ConstExpr.GetBoolValue(), nil
|
||||
default:
|
||||
return nil, errors.New("unexpected constant type")
|
||||
}
|
||||
return nil, errors.New("invalid constant expression")
|
||||
}
|
||||
|
|
|
@ -31,7 +31,7 @@ func TestRestoreExprToSQL(t *testing.T) {
|
|||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
parsedExpr, err := filter.Parse(tt.filter)
|
||||
parsedExpr, err := filter.Parse(tt.filter, filter.MemoFilterCELAttributes...)
|
||||
require.NoError(t, err)
|
||||
result, err := RestoreExprToSQL(parsedExpr.GetExpr())
|
||||
require.NoError(t, err)
|
||||
|
|
Loading…
Reference in a new issue