github.com/GuanceCloud/cliutils@v1.1.21/pipeline/ptinput/funcs/fn_uppercase.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 "strings" 11 12 "github.com/GuanceCloud/cliutils/pipeline/ptinput" 13 "github.com/GuanceCloud/platypus/pkg/ast" 14 "github.com/GuanceCloud/platypus/pkg/engine/runtime" 15 "github.com/GuanceCloud/platypus/pkg/errchain" 16 ) 17 18 func UppercaseChecking(ctx *runtime.Task, funcExpr *ast.CallExpr) *errchain.PlError { 19 if len(funcExpr.Param) != 1 { 20 return runtime.NewRunError(ctx, fmt.Sprintf( 21 "func %s expects 1 arg", funcExpr.Name), funcExpr.NamePos) 22 } 23 if _, err := getKeyName(funcExpr.Param[0]); err != nil { 24 return runtime.NewRunError(ctx, err.Error(), funcExpr.Param[0].StartPos()) 25 } 26 return nil 27 } 28 29 func Uppercase(ctx *runtime.Task, funcExpr *ast.CallExpr) *errchain.PlError { 30 if len(funcExpr.Param) != 1 { 31 return runtime.NewRunError(ctx, fmt.Sprintf( 32 "func %s expects 1 args", 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 cont, err := ctx.GetKeyConv2Str(key) 41 if err != nil { 42 l.Debug(err) 43 return nil 44 } 45 46 v := strings.ToUpper(cont) 47 48 _ = addKey2PtWithVal(ctx.InData(), key, v, ast.String, ptinput.KindPtDefault) 49 50 return nil 51 }