github.com/GuanceCloud/cliutils@v1.1.21/pipeline/ptinput/funcs/fn_getkey.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/platypus/pkg/ast" 12 "github.com/GuanceCloud/platypus/pkg/engine/runtime" 13 "github.com/GuanceCloud/platypus/pkg/errchain" 14 ) 15 16 func GetkeyChecking(ctx *runtime.Task, funcExpr *ast.CallExpr) *errchain.PlError { 17 if len(funcExpr.Param) != 1 { 18 return runtime.NewRunError(ctx, fmt.Sprintf( 19 "func %s expected 1 args", funcExpr.Name), funcExpr.NamePos) 20 } 21 22 if _, err := getKeyName(funcExpr.Param[0]); err != nil { 23 return runtime.NewRunError(ctx, err.Error(), funcExpr.Param[0].StartPos()) 24 } 25 26 return nil 27 } 28 29 func Getkey(ctx *runtime.Task, funcExpr *ast.CallExpr) *errchain.PlError { 30 if len(funcExpr.Param) != 1 { 31 return runtime.NewRunError(ctx, fmt.Sprintf("func %s expected 1 args", 32 funcExpr.Name), funcExpr.NamePos) 33 } 34 35 key, err := getKeyName(funcExpr.Param[0]) 36 if err != nil { 37 return runtime.NewRunError(ctx, err.Error(), funcExpr.Param[0].StartPos()) 38 } 39 40 if val, dtype, err := getPtKey(ctx.InData(), key); err != nil { 41 ctx.Regs.ReturnAppend(nil, ast.Nil) 42 } else { 43 ctx.Regs.ReturnAppend(val, dtype) 44 } 45 46 return nil 47 }