github.com/GuanceCloud/cliutils@v1.1.21/pipeline/ptinput/funcs/fn_addpattern.go (about) 1 // Unless explicitly stated otherwise all files in this repository are licensed 2 // under the MIT License. 3 // This product includes software developed at Guance Cloud (https://www.guance.com/). 4 // Copyright 2021-present Guance, Inc. 5 6 package funcs 7 8 import ( 9 "fmt" 10 11 "github.com/GuanceCloud/grok" 12 "github.com/GuanceCloud/platypus/pkg/ast" 13 "github.com/GuanceCloud/platypus/pkg/engine/runtime" 14 "github.com/GuanceCloud/platypus/pkg/errchain" 15 ) 16 17 func AddPatternChecking(ctx *runtime.Task, funcExpr *ast.CallExpr) *errchain.PlError { 18 if len(funcExpr.Param) != 2 { 19 return runtime.NewRunError(ctx, fmt.Sprintf( 20 "func %s expected 2 args", funcExpr.Name), funcExpr.NamePos) 21 } 22 23 var name, pattern string 24 switch funcExpr.Param[0].NodeType { //nolint:exhaustive 25 case ast.TypeStringLiteral: 26 name = funcExpr.Param[0].StringLiteral().Val 27 default: 28 return runtime.NewRunError(ctx, fmt.Sprintf("expect StringLiteral, got %s", 29 funcExpr.Param[0].NodeType), funcExpr.NamePos) 30 } 31 32 switch funcExpr.Param[1].NodeType { //nolint:exhaustive 33 case ast.TypeStringLiteral: 34 pattern = funcExpr.Param[1].StringLiteral().Val 35 default: 36 return runtime.NewRunError(ctx, fmt.Sprintf("expect StringLiteral, got %s", 37 funcExpr.Param[1].NodeType), funcExpr.Param[1].StartPos()) 38 } 39 40 deP, err := grok.DenormalizePattern(pattern, ctx) 41 if err != nil { 42 return runtime.NewRunError(ctx, err.Error(), funcExpr.NamePos) 43 } 44 ctx.SetPattern(name, deP) 45 return nil 46 } 47 48 func AddPattern(ctx *runtime.Task, funcExpr *ast.CallExpr) *errchain.PlError { 49 return nil 50 }