github.com/GuanceCloud/cliutils@v1.1.21/pipeline/ptinput/funcs/fn_dropkey.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 DropkeyChecking(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 Dropkey(ctx *runtime.Task, funcExpr *ast.CallExpr) *errchain.PlError {
    30  	if len(funcExpr.Param) != 1 {
    31  		return runtime.NewRunError(ctx, fmt.Sprintf(
    32  			"func %s expected 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  	deletePtKey(ctx.InData(), key)
    40  
    41  	return nil
    42  }