Skip to content

Latest commit

 

History

History
75 lines (56 loc) · 2.43 KB

readme.md

File metadata and controls

75 lines (56 loc) · 2.43 KB

Overview

This repo is an example of how we might create an Microsoft Azure Function using Go language. Go lang doesn't have an existing template whilst using Azure Functions Core Tools. As such we need to use a "custom handler" to run Go lang applications either locally or in the cloud.

Prerequisites

Running the sample App

  • Go to the root of this repo

  • Check make options: Running

  • Run make run to start the app:

    Running

  • Click on http://localhost:7071/api/func1 to browse the app

App details

The application is enclosed in the func1 folder in hello.go. It uses a standard http.ServeMux with a single registered route:

	mux := http.NewServeMux()
	route := fmt.Sprintf("/api/%s", getDirName())
	mux.HandleFunc(route, helloHandler)

host.json

The host.json file in the root tells the Azure Function runtime the name and path of the binary to run:

  "customHandler": {
    "enableForwardingHttpRequest": true,
    "description": {
      "defaultExecutablePath": "out/func1",
      "workingDirectory": "out",
      "arguments": [

      ]
    }
  }

function.json

The function.json file in the func1 directory tells the Azure function runtime to use an httpTrigger binding as the event to trigger any request/response for the func1 functions app:

{
  "bindings": [
    {
      "authLevel": "anonymous",
      "type": "httpTrigger",
      "direction": "in",
      "name": "req",
      "methods": [
        "get",
        "post"
      ]
    },
    {
      "type": "http",
      "direction": "out",
      "name": "res"
    }
  ]
}