Rediger

Azure Functions Go developer reference

The Azure Functions Go worker lets you write event-driven functions in Go. This guide covers the programming model, project structure, triggers, and deployment.

For concepts shared across languages, see the Azure Functions developer reference.

Hosting plan support

The Go runtime is supported on Linux with the following hosting plans:

Hosting plan Support level
Flex Consumption Generally available (GA)
Elastic Premium Preview
Dedicated (App Service) Preview

Go function apps aren't supported on Windows or the Linux Consumption plan.

Getting started

To create and deploy your first Go function on Flex Consumption, follow the command line quickstart.

Prerequisites

  • Go 1.24 or later
  • Azure Functions Core Tools version 4.16 or later. Run func --version to verify your installed version.
  • Azure CLI version 2.87.0 or later, when you create Azure resources or deploy packages to Azure. Run az version to verify your installed version.

Programming model

The Go worker uses a code-first programming model. You define serverless functions and their triggers by using idiomatic Go handlers.

Entry point

In main(), create a FunctionApp, register your functions, and start the worker:

package main

import (
    "fmt"
    "net/http"

    "github.com/azure/azure-functions-golang-worker/sdk"
    "github.com/azure/azure-functions-golang-worker/worker"
)

func main() {
    app := sdk.FunctionApp()

    app.HTTP("hello", hello,
        sdk.WithMethods("GET", "POST"),
        sdk.WithAuth("anonymous"),
    )

    worker.Start(app)
}

func hello(w http.ResponseWriter, r *http.Request) {
    name := r.URL.Query().Get("name")
    if name == "" {
        name = "world"
    }
    fmt.Fprintf(w, "Hello, %s!", name)
}

Function registration

Call a trigger-specific method on the App object with a function name, handler, and options. In the preceding example, sdk.WithMethods() sets the allowed HTTP methods and sdk.WithAuth() sets the authorization level.

See Triggers for handler signatures and registration methods, and the Go worker samples for service-specific configuration.

Project structure

A Go Functions project is a standard Go module. func init --worker-runtime go generates:

my-function-app/
├── host.json              # Host configuration
├── local.settings.json    # Local settings (connection strings, app settings)
├── go.mod                 # Go module file
├── go.sum                 # Go module checksums
└── main.go                # Entry point with function registrations

host.json

Configure the Functions host in host.json. See the host.json reference.

local.settings.json

Store local app settings and connection strings in local.settings.json. This file isn't published to Azure. For more information, see Local settings file.

Triggers

The following sections describe Go-specific handler signatures and registration methods. For shared trigger and binding concepts, see Azure Functions triggers and bindings.

Typed trigger payloads

For most triggers, the host sends serialized payloads over gRPC and the worker decodes them into typed Go values. These handlers don't require Azure SDK clients.

Trigger Handler signature Registration method
HTTP func(http.ResponseWriter, *http.Request) app.HTTP()
Timer TimerHandler app.Timer()
Azure Queue Storage QueueHandler app.Queue()
Azure Cosmos DB func(context.Context, []bindings.CosmosDocument) error app.CosmosDB()
Azure Service Bus (Queue) ServiceBusHandler app.ServiceBusQueue()
Azure Service Bus (Topic) ServiceBusHandler app.ServiceBusTopic()
Event Hubs EventHubHandler app.EventHub()
Event Grid EventGridHandler app.EventGrid()
Azure SQL func(context.Context, []bindings.SQLChange) error app.SQL()

Event Hubs and Service Bus also support strongly typed batch handlers through app.EventHubBatch(), app.ServiceBusQueueBatch(), and app.ServiceBusTopicBatch().

SDK type bindings

Blob Storage triggers pass an authenticated *blob.Client to the handler instead of sending blob contents over gRPC. This approach lets you stream large blobs without buffering the full payload. Register the trigger with app.Blob() and add a blank import for triggers/blob, as shown in the following example.

Blob trigger example

package main

import (
    "context"
    "fmt"
    "io"
    "log"

    "github.com/Azure/azure-sdk-for-go/sdk/storage/azblob/blob"
    "github.com/azure/azure-functions-golang-worker/sdk"
    _ "github.com/azure/azure-functions-golang-worker/triggers/blob"
    "github.com/azure/azure-functions-golang-worker/worker"
)

func main() {
    app := sdk.FunctionApp()
    app.Blob("processBlobTrigger", processBlob,
        sdk.WithPath("samples-workitems/{name}"),
        sdk.WithConnection("AzureWebJobsStorage"),
    )
    worker.Start(app)
}

func processBlob(ctx context.Context, client *blob.Client) error {
    get, err := client.DownloadStream(ctx, nil)
    if err != nil {
        return fmt.Errorf("download error: %w", err)
    }
    data, _ := io.ReadAll(get.Body)
    get.Body.Close()
    log.Printf("Blob size: %d bytes", len(data))
    return nil
}

Generic host triggers

Use app.GenericTrigger() when a compatible host extension provides a trigger that doesn't have a dedicated Go registration method. Generic triggers support raw text, byte slices, and JSON-compatible Go types:

app.GenericTrigger("echoTool", echoTool, &bindings.GenericTrigger{
    Type:     "mcpToolTrigger",
    Name:     "call",
    DataType: "string",
    Properties: map[string]any{
        "toolName":       "echo",
        "description":    "Echo text using a generic Go trigger",
        "toolProperties": `[{"propertyName":"text","propertyType":"string","description":"Text to echo","isRequired":true}]`,
    },
})

The compatible host extension must be installed. Generic trigger registration doesn't provide HTTP handling, SDK client injection, Durable Functions replay, or service-specific message settlement. For complete examples, see the generic triggers sample.

HTTP triggers

HTTP trigger handlers use standard Go net/http types: http.ResponseWriter and *http.Request. The entry point example shows a complete handler and its registration. For shared HTTP trigger configuration, see Azure Functions HTTP trigger.

HTTP streaming

The Go worker supports HTTP streaming for scenarios like server-sent events or sending large response data:

func streamHandler(w http.ResponseWriter, r *http.Request) {
    flusher, ok := w.(http.Flusher)
    if !ok {
        http.Error(w, "streaming not supported", http.StatusInternalServerError)
        return
    }

    w.Header().Set("Content-Type", "text/event-stream")
    for i := 0; i < 10; i++ {
        fmt.Fprintf(w, "data: message %d\n\n", i)
        flusher.Flush()
    }
}

Timer trigger

Use app.Timer() with sdk.WithSchedule() to register a handler that receives bindings.TimerInfo. For schedule syntax and shared configuration, see Azure Functions timer trigger.

app.Timer("myScheduledFunc", timerHandler,
    sdk.WithSchedule("0 */5 * * * *"),
)

func timerHandler(ctx context.Context, timer bindings.TimerInfo) error {
    log.Printf("Timer trigger executed at: %s", timer.ScheduleStatus.Next)
    return nil
}

Durable Functions (preview)

Durable Functions support for Go is in preview. Use middleware/durabletask to register orchestrators and activities before calling app.Use():

durable := durabletask.Middleware()
durable.Orchestrator("HelloCities", helloCities)
durable.Activity("SayHello", sayHello)
app.Use(durable)

Durable Functions for Go requires Go 1.25 or later and the Durable Task extension version 3.15.0 or later. The Azure Functions Go worker doesn't currently support durable entities. For a complete application, see the Durable Functions sample.

Dependency management

Go code projects use standard Go modules for dependency management.

  1. Initialize a new module:

    go mod init myapp
    
  2. Add the Azure Functions Go worker SDK:

    go get github.com/azure/azure-functions-golang-worker
    

    For blob trigger support, the dependency is included automatically via the blank import of triggers/blob.

  3. Tidy dependencies:

    go mod tidy
    

Run local

Use Azure Functions Core Tools to run your project locally:

func start

Core Tools reads FUNCTIONS_WORKER_RUNTIME = "native" from local.settings.json and identifies Go from go.mod. It runs go build -o bin/app . for your local operating system, starts the host, and displays your function endpoints. The host communicates with the compiled binary over gRPC.

Use local.settings.json to configure environment variables for local development:

{
    "IsEncrypted": false,
    "Values": {
        "AzureWebJobsStorage": "",
        "FUNCTIONS_WORKER_RUNTIME": "native"
    }
}

The generated AzureWebJobsStorage value is empty for Go projects. Set it to a storage account connection string or UseDevelopmentStorage=true when you use triggers that require host storage during local development.

Deployment

Compilation and packaging

Core Tools builds your project before publishing or packaging it. func pack builds a Linux x64 binary at bin/app and creates a deployable .zip package.

In the deployment package, Core Tools places the binary at the root as app.

If you use func pack --no-build, you must build the Linux x64 binary before packaging:

CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o bin/app .

Deploy with Core Tools

Use func azure functionapp publish to deploy your Go project to an existing Flex Consumption function app in Azure:

func azure functionapp publish <APP_NAME>

Replace <APP_NAME> with the name of your function app.

For Linux Elastic Premium and Dedicated apps, see Preview deployment settings.

Deploy a zip package

To package and deploy separately, use func pack and the Azure CLI. For Elastic Premium or Dedicated apps, first apply the preview deployment settings.

  1. Create a deployable zip artifact:

    func pack
    
  2. Deploy the package by using the Azure CLI:

    az functionapp deployment source config-zip --resource-group <RESOURCE_GROUP> --name <APP_NAME> --src <ZIP_FILE_PATH> --build-remote false
    

Replace <ZIP_FILE_PATH> with the path reported by func pack. The package is ready to run, so keep remote builds disabled.

After the deployment completes, invoke your HTTP trigger endpoint to verify the app, including a function key if required.

Preview deployment settings for Linux Elastic Premium and Dedicated plans

Before deploying to Linux Elastic Premium or Dedicated (App Service), set WEBSITE_RUN_FROM_PACKAGE to 1 in the Azure portal or with the Azure CLI:

az functionapp config appsettings set --resource-group <RESOURCE_GROUP> --name <APP_NAME> --settings WEBSITE_RUN_FROM_PACKAGE=1

Important

Don't add WEBSITE_RUN_FROM_PACKAGE to Flex Consumption apps, which manage package deployment differently.

On Dedicated plans, also enable Always On. Wait for the app restart to complete before deploying your package.

Then follow Deploy a zip package.

Docker support

You can run Go code projects in containers. Initialize a project with Docker support:

func init --worker-runtime go --docker

The command generates a Dockerfile along with the standard project files.

Telemetry and observability

Use context-aware log/slog methods, such as slog.InfoContext, to correlate structured logs with the current invocation. To enable OpenTelemetry, configure the Functions host and register the Go worker OpenTelemetry middleware. See Use OpenTelemetry with Azure Functions.

Known limitations

  • func new isn't supported. Add functions by editing main.go directly.
  • Only the dedicated triggers listed in Triggers and compatible generic host triggers are supported.
  • Additional input bindings and non-HTTP output bindings aren't currently supported.
  • Go packaging in Core Tools currently targets Linux x64 apps.

Next steps