Skip to content

katasec/gofnapp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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"
    }
  ]
}

About

An example of a Golang Azure Function App

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published