This sample shows how to host multiple Azure functions in Golang.

azure-function-custom-handler-with-golang

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.

readme-azf-design-diagram

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.

How to run this project

It is recommended that you use a devcontainer.

Prerequisites

  1. Docker is installed and running on your machine
  2. Visual Studio Code(VScode) is installed as a code editor

Launch devcontainer

  1. Make sure your docker is running
  2. Open this project with VScode
  3. Click the green icon in bottom left labelled "Open in Container"

Build the project

  1. Open the terminal in VScode
  2. Run make build
  3. Make sure the app file is created the root folder

Run the project

  1. Open the terminal in VScode
  2. Run make start
  3. Comfirm the endpoint URLs appear in the terminal

Send a HTTP request

  1. Sample request for /drink endpoint

    ' ## DELETE curl --location --request DELETE 'http://localhost:7071/api/drink' \ --header 'id: '">
    ## 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: 
          
           '
          
    
    ## DELETE
    curl --location --request DELETE 'http://localhost:7071/api/drink' \
    --header 'id: 
          
           '
          
  2. Sample request for /drinks endpoint

    ## GET
    curl --location --request GET 'http://localhost:7071/api/drinks'

Run unit tests

  1. Open the terminal in VScode
  2. Run make test
  3. Run make coverage

Run lint

  1. Open the terminal in VScode
  2. Run make lint

Deploy

There are two different methods to deploy this project.

Method 1: Using VSCode

Please follow Publish the project to Azure

Method 2: Using a Pipeline

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]

  1. Publish: Code
  2. Runtime stack: Custom Handler
  3. Version: custom

[Hosting]

  1. Operating System: Linux
  2. 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.

Github

  1. Replace the .github folder and its contents with pipelines/.github
  2. Add credentials in Github secret
    1. Create a Service Principal and Add the Service Principal in Secrets as AZURE_CREDENTIALS
    2. Add the Azure function name in Secrets as FUNCTION_APP

Azure DevOps

  1. Update variables in azure-pipelines.yml
    1. $(AZURE_SUBSCRIPTION) with your subscription (format: subscription_name(subscription_id))
    2. $(FUNCTION_APP) with the name of your Azure function
  2. In Azure DevOps, Navigate to Pipelines > New pipeline
    1. Connect: Azure Repos Git(YAML) option
    2. Select: Your repo
    3. Configure: Existing Azure Pipelines YAML file
    4. Set main branch and /pipeline/azure-pipelines.yml path
    5. Hit Run button. You may see "Permission needed" error at the first time. If you have this error, please grant permission to the subscription.

Gitlab

  1. In Gitlab, Navigate to Settings > CI/CD
    1. In the General pipelines, put pipeline/.gitlab-ci.yml in the CI/CD configuration file textbox.
    2. In Variables, create APPLICATION_ID, APPLICATION_SECRET and TENANT_ID variables. You can find the values in the Azure portal.
  2. In the .gitlab-ci.yml file
    1. Update the REPO_NAME value with your Gitlab repositiory.
    2. Update the FUNCTION_APP value in .gitlab-ci.yml file with the name of your Azure function.

Resources

Owner
Azure Samples
Microsoft Azure code samples and examples in .NET, Java, Python, Node.js, PHP and Ruby
Azure Samples
Similar Resources

Azure translation SDK For Golang

azure-translate Azure translation SDK Example key := "YOUR-SUBSCRIPTION-KEY" location := "global" client := translate.NewClient(key, location) result

Mar 15, 2022

How to get a Go / Golang app using the Gin web framework running natively on Windows Azure App Service WITHOUT using a Docker container

Go on Azure App Service View the running app - https://go-azure-appservice.azurewebsites.net 😎 This is an example repo of how to get a Go / Golang a

Nov 28, 2022

Azure Kubernetes Service (AKS) advanced networking (CNI) address space calculator.

aksip Azure Kubernetes Service (AKS) advanced networking (CNI) address space calculator. Download Download the the latest version from the releases pa

Dec 23, 2022

A tool to bring existing Azure resources under Terraform's management

Azure Terrafy A tool to bring your existing Azure resources under the management of Terraform. Install go install github.com/magodo/aztfy@latest Usage

Dec 9, 2021

Kubernetes operator for the Azure DevOps pipe-line agents

adoagent-operator Kubernetes operator for the Azure DevOps pipe-line agents init.sh #!/bin/bash # docker and github repo username export USERNAME='ba

Nov 11, 2021

Kubernetes operator for the Azure DevOps self-hosted pipe-line agent.

Kubernetes operator for the Azure DevOps self-hosted pipe-line agent. The operator adds an extra layer of configuration on top of the default images like: proxy settings, pool settings and auth keys.

Sep 1, 2022

A tool to bring existing Azure resources under Terraform's management

Azure Terrafy A tool to bring your existing Azure resources under the management of Terraform. Goal Azure Terrafy imports the resources inside a resou

Jan 1, 2023

Simple tool to move Azure resources based on Terraform state

aztfmove Simple tool to move Azure resources based on Terraform state Goal It is sometimes inevitable to move Azure resources to a new subscription or

Dec 29, 2022

Make any web accessible from your own host / domain

Make any web accessible from your own host / domain

Web Mirror Based on reverseproxy Solution for: Website that only set 'X-Frame-Options' to 'sameorigin'. Hide website real url Content interception & m

May 31, 2022
azqlite is a lightweight wrapper around Azure's SDK to interact with the Azure Storage Queue service in a simpler and more idiomatic way.

azqlite azqlite is a lightweight wrapper around github.com/Azure/azure-storage-queue-go to interact with the Azure Storage Queue service in a simpler

Mar 12, 2022
Display (Namespace, Pod, Container, Primary PID) from a host PID, fails if the target process is running on host

Display (Namespace, Pod, Container, Primary PID) from a host PID, fails if the target process is running on host

Oct 17, 2022
Sample Hello World Pulumi Program for Azure

Overview This is a standard hello world style Pulumi program for Azure straight from the Pulumi docs. This is a sample repo used to test Pulumi's Auto

Jan 13, 2022
EdgeDB-Golang-Docker-Sample - The sample of connection between EdgeDB Server and Go Echo API Server

EdgeDB Golang Docker Sample 『Go + Docker Composeを使ってEdgeDBを動かしてみた』のサンプルコードです。 使い

Nov 2, 2022
Using the Golang search the Marvel Characters. This project is a web based golang application that shows the information of superheroes using Marvel api.
Using the Golang search the Marvel Characters. This project is a web based golang application that shows the information of superheroes using Marvel api.

marvel-universe-web using the Golang search the Marvel Universe Characters About The Project This project is a web based golang application that shows

Oct 10, 2021
S3pd - CLI utility that downloads multiple s3 objects at a time, with multiple range-requests issued per object

S3 Parallel Downloader CLI utility that downloads multiple s3 objects at a time,

May 13, 2022
A demo repository that shows CI/CD integration using DroneCI + ArgoCD + Kubernetes.
A demo repository that shows CI/CD integration using DroneCI + ArgoCD + Kubernetes.

CI/CD Demo This is the demo repo for my blog post. This tutorial shows how to build CI/CD pipeline with DroneCI and ArgoCD. In this demo, we use Drone

Oct 18, 2022
The example shows how to build a simple multi-tier web application using Kubernetes and Docker
The example shows how to build a simple multi-tier web application using Kubernetes and Docker

Guestbook Example This example shows how to build a simple multi-tier web application using Kubernetes and Docker. The application consists of a web f

Nov 15, 2021
A simple Go app and GitHub workflow that shows how to use GitHub Actions to test, build and deploy a Go app to Docker Hub

go-pipeline-demo A repository containing a simple Go app and GitHub workflow that shows how to use GitHub Actions to test, build and deploy a Go app t

Nov 17, 2021
Kubectl plugin shows pod x node matrix with suitable colors to mitigate troubleshooting effort.

kubectl-pod-node-matrix WORK IN PROGRESS!! This plugin shows pod x node matrix with suitable colors to mitigate troubleshooting effort. Details Troubl

May 11, 2022