This repository contains kind of a transcript for the YouTube video Serverless Go in Azure Functions with custom handlers by Anthony Chu. The video contains a lot of helpful information about custom handlers and beyond. This repository contains the code for the single steps Anthony is executing in his video. Each step is represented in an own branch. The corresponding starting point of the video is referenced accordingly in the sections describing the branch.
The complete tutorial is build in WSL2 on Windows10 to mimic the non-Windows environment of the original video. I used the Ubuntu 20.04 image. Beside having WSL2 running you also need some further things to be installed in WSL2:
- Go via apt i.e.
sudo apt-get install golang
. - Node e.g. installed via NVM (Node version manager) as described here
- Azurite as storage emulator installed via npm. I also created a dedicated location for storing the data in
~/azurite_store
. - VS Code Azure Function Extension
- VS Code Azure Storage Extension
You should also install the Azure Storage Explorer on your Windows host. This can directly access Azurite via port-forwarding from WSL2.
As the local.settings.json
file is usually not committed I created a placeholder file called local.settings sample.json
that can serve as a template.
YouTube Reference: Link
Branch: main
Hints:
- Do not forget to build the go file.
- Ports are forwarded from WSL2, so you can directly access the endpoints from your Windows host.
YouTube Reference: Link
Branch: function_custom_handler
Hints:
- Set the
defaultExecutablePath
toserver
in thehost.json
for thecustom handler
- noserver.exe
as we are on Linux. - Add the parameter
enableForwardingHttpRequest
and set it totrue
. - Adopt the
server.go
to fetch the port from the environment variableFUNCTIONS_CUSTOMHANDLER_PORT
. - Do not forget to build the go file.
YouTube Reference: Link
Branch: queue_trigger
Hints:
- Create a new function with a queue trigger.
- Adopt the
server.go
file to handle a new route. See code for details. - Do not forget to build the go file.
- Do not forget to set the
AzureWebJobsStorage
parameter toUseDevelopmentStorage=true;
in thelocal.settings.json
file. - Do not forget to launch Azurite before starting the function via
azurite --silent --location ~/azurite_store
.
YouTube Reference: Link
Branch: cross_compile
Hints:
- As deployment is done to a Windows app on Azure we need to cross-compile the app. The relevant statement is available in the file
crosscompile.sh
. - Do not forget to execute
chmod +x
on the file to make it executable. - Do not forget to set the
defaultExecutablePath
toserver.exe
in thehost.json
. - In order to be able to proceed with the local scenario, we override the setting in
host.json
the setting in thelocal.settings.json
via setting teh parameterAzureFunctionsJobHost__customHandler__description__defaultExecutablePath
to the valueserver
(Remark: This can be done with any parameter inhost.json
using the parameter path separated by__
).
YouTube Reference: Link
Branch: routing
Hints:
- Adopt the go file and do not forget to register a new generic route.
- Do not forget to build the go file.
- Rename the function to
all
. - Add the route property to the
function.json
file for the all function and set it to a wildcard.
YouTube Reference: Link
Branch: debug
Hints:
- Add the property
logLevel
tohost.json
and set it to{ "default": "Trace" }
in order to get an extensive log output in your console.