Azure函数powershell脚本,如何在同一个Azure函数中实现多个辅助函数?

问题描述 投票:0回答:1

我创建了一个 Azure 函数。在这个函数中我想实现一些辅助函数。我不想导入模块,但想在函数内添加辅助函数。我怎样才能实现这个?

例如

using namespace System.Net

function HelperFunctionCreateTab {param([string] $tabName, [string] $channelName)
    // some helper function logic
}

param($Request, $TriggerMetadata)
        
   Write-Output "START"
    
   // some main function logic

   HelperFunctionCreateTab -tabName "tabX" -channelName "channelY"

   // some main function logic
    
   Write-Output "START"
powershell azure-functions helper
1个回答
0
投票

如果您打算在同一个 Azure 函数中实现辅助函数,那么您需要将其添加到

param
块之后。

param
块需要位于顶部,位于函数中的
using
块之后,否则您将收到输入绑定错误。

我正在使用下面的代码来实现辅助功能。

using namespace System.Net

# Input bindings are passed in via param block.
param($Request, $TriggerMetadata)

function HelperFunctionCreateTab {
    param([string] $tabName, [string] $channelName)
    
    # Helper function logic
    Write-Output "Creating tab '$tabName' in channel '$channelName'"
}

Write-Output "START"

# Call the helper function
HelperFunctionCreateTab -tabName $Request.Query.tabName -channelName $Request.Query.channelName

Write-Output "END"

# Associate values to output bindings by calling 'Push-OutputBinding'.
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{
    StatusCode = [HttpStatusCode]::OK
    Body = "Function execution completed."
})

输出-

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.