This sample shows how to host multiple Azure functions in Golang. To learn more about this sample please check out the full description in this blog article.
There is a function "drink" which can be used to create, update, or delete your favorite drink, and a "drinks" method to retrieve all the previously saved drinks.
It is recommended that you use a devcontainer.
- Docker is installed and running on your machine
- Visual Studio Code(VScode) is installed as a code editor
⚠️ Important: AArch64 / arm64 Architecture Notice (24 June 2025)Known Issue: The
azure-functions-core-toolsdevcontainer feature does not work on AArch64 / arm64 architectures due to upstream limitations.
- If you are using an AArch64 / arm64 system, you must comment out the
azure-functions-core-toolsfeature in your.devcontainer/devcontainer.json.- However,
azure-functions-core-toolsis still required for local development and running Azure Functions.- You will need to install Azure Functions Core Tools manually inside your devcontainer (or on your local machine, if not using a devcontainer).
For installation instructions and the latest documentation, see the official repo: Azure/azure-functions-core-tools
- Make sure your docker is running
- Open this project with VScode
- Click the green icon in bottom left labelled "Open in Container"
- Open the terminal in VScode
- Run
make build - Make sure the
appfile is created the root folder
- Open the terminal in VScode
- Run
make start - Choose
6. customfor worker runtime - Comfirm the endpoint URLs appear in the terminal
-
Sample request for
/drinkendpoint## POST curl --location --request POST 'http://localhost:7071/api/drink' \ --header 'Content-Type: application/json' \ --data-raw '{ "name":"Water", "price":1 }' ## GET curl --location --request GET 'http://localhost:7071/api/drink' \ --header 'id: <uuid>' ## DELETE curl --location --request DELETE 'http://localhost:7071/api/drink' \ --header 'id: <uuid>'
-
Sample request for
/drinksendpoint## GET curl --location --request GET 'http://localhost:7071/api/drinks'
- Open the terminal in VScode
- Run
make test - Run
make coverage
- Open the terminal in VScode
- Run
make lint
There are two different methods to deploy this project.
Please follow Publish the project to Azure
This repo contains yaml pipelines for Github, Azure DevOps and Gitlab. The pipelines folder contains the yaml for Github, Azure Pipelines and Gitlab. Please choose the appropriate yaml for your choice of platform.
To deploy this project using a pipeline, you need to set up the Azure Function in Azure yourself in advance.
How to set up a custom handler Azure Function
Start by searching for Function App in the Azure Portal and click Create. The important settings for this are below, other settings you can use default or your own preferences.
[Basic]
- Publish: Code
- Runtime stack: Custom Handler
- Version: custom
[Hosting]
- Operating System: Linux
- Plan type: Consumption (Serverless)
For some of these inputs it is important to keep them secure, so please consider using an secret management tool or service such as Azure Key Vault.
- Replace the
.githubfolder and its contents withpipelines/.github - Add credentials in Github secret
- Create a Service Principal and Add the Service Principal in Secrets as
AZURE_CREDENTIALS - Add the Azure function name in Secrets as
FUNCTION_APP
- Create a Service Principal and Add the Service Principal in Secrets as
- Update variables in
azure-pipelines.yml$(AZURE_SUBSCRIPTION)with your subscription (format:subscription_name(subscription_id))$(FUNCTION_APP)with the name of your Azure function
- In Azure DevOps, Navigate to Pipelines > New pipeline
- Connect: Azure Repos Git(YAML) option
- Select: Your repo
- Configure: Existing Azure Pipelines YAML file
- Set
mainbranch and/pipeline/azure-pipelines.ymlpath - Hit
Runbutton. You may see "Permission needed" error at the first time. If you have this error, please grant permission to the subscription.
- In Gitlab, Navigate to Settings > CI/CD
- In the General pipelines, put
pipeline/.gitlab-ci.ymlin the CI/CD configuration file textbox. - In Variables, create
APPLICATION_ID,APPLICATION_SECRETandTENANT_IDvariables. You can find the values in the Azure portal.
- In the General pipelines, put
- In the
.gitlab-ci.ymlfile- Update the
REPO_NAMEvalue with your Gitlab repositiory. - Update the
FUNCTION_APPvalue in.gitlab-ci.ymlfile with the name of your Azure function.
- Update the
