From c90f37f138a4d74a6f0e3f281ec98e4ed65d6ce6 Mon Sep 17 00:00:00 2001 From: Anish Sharma Date: Thu, 18 Nov 2021 11:58:48 +0530 Subject: [PATCH 1/3] created an example http function --- .funcignore | 4 ++++ .gitignore | 28 ++++++++++++++++++++++++++++ .vscode/extensions.json | 5 +++++ .vscode/settings.json | 6 ++++++ .vscode/tasks.json | 11 +++++++++++ HttpExample/function.json | 19 +++++++++++++++++++ handler.go | 27 +++++++++++++++++++++++++++ host.json | 23 +++++++++++++++++++++++ 8 files changed, 123 insertions(+) create mode 100644 .funcignore create mode 100644 .gitignore create mode 100644 .vscode/extensions.json create mode 100644 .vscode/settings.json create mode 100644 .vscode/tasks.json create mode 100644 HttpExample/function.json create mode 100644 handler.go create mode 100644 host.json diff --git a/.funcignore b/.funcignore new file mode 100644 index 0000000..414df2f --- /dev/null +++ b/.funcignore @@ -0,0 +1,4 @@ +.git* +.vscode +local.settings.json +test \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..6bbc18e --- /dev/null +++ b/.gitignore @@ -0,0 +1,28 @@ + +# Azure Functions artifacts +bin +obj +appsettings.json +local.settings.json + +# Azurite artifacts +__blobstorage__ +__queuestorage__ +__azurite_db*__.json + +# Go +# Binaries for programs and plugins +*.exe +*.exe~ +*.dll +*.so +*.dylib + +# Test binary, built with `go test -c` +*.test + +# Output of the go coverage tool, specifically when used with LiteIDE +*.out + +# Dependency directories (remove the comment below to include it) +# vendor/ \ No newline at end of file diff --git a/.vscode/extensions.json b/.vscode/extensions.json new file mode 100644 index 0000000..26786f9 --- /dev/null +++ b/.vscode/extensions.json @@ -0,0 +1,5 @@ +{ + "recommendations": [ + "ms-azuretools.vscode-azurefunctions" + ] +} diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..58ff4e6 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,6 @@ +{ + "azureFunctions.deploySubpath": ".", + "azureFunctions.projectLanguage": "Custom", + "azureFunctions.projectRuntime": "~4", + "debug.internalConsoleOptions": "neverOpen" +} \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 0000000..17983f9 --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,11 @@ +{ + "version": "2.0.0", + "tasks": [ + { + "type": "func", + "command": "host start", + "problemMatcher": "$func-watch", + "isBackground": true + } + ] +} \ No newline at end of file diff --git a/HttpExample/function.json b/HttpExample/function.json new file mode 100644 index 0000000..7eb1f8f --- /dev/null +++ b/HttpExample/function.json @@ -0,0 +1,19 @@ +{ + "bindings": [ + { + "authLevel": "anonymous", + "type": "httpTrigger", + "direction": "in", + "name": "req", + "methods": [ + "get", + "post" + ] + }, + { + "type": "http", + "direction": "out", + "name": "res" + } + ] +} diff --git a/handler.go b/handler.go new file mode 100644 index 0000000..32e8f1e --- /dev/null +++ b/handler.go @@ -0,0 +1,27 @@ +package main + +import ( + "fmt" + "log" + "net/http" + "os" +) + +func helloHandler(w http.ResponseWriter, r *http.Request) { + message := "This HTTP triggered function executed successfully. Pass a name in the query string for a personalized response.\n" + name := r.URL.Query().Get("name") + if name != "" { + message = fmt.Sprintf("Hello, %s. This HTTP triggered function executed successfully.\n", name) + } + fmt.Fprint(w, message) +} + +func main() { + listenAddr := ":8080" + if val, ok := os.LookupEnv("FUNCTIONS_CUSTOMHANDLER_PORT"); ok { + listenAddr = ":" + val + } + http.HandleFunc("/api/HttpExample", helloHandler) + log.Printf("About to listen on %s. Go to https://127.0.0.1%s/", listenAddr, listenAddr) + log.Fatal(http.ListenAndServe(listenAddr, nil)) +} diff --git a/host.json b/host.json new file mode 100644 index 0000000..fc93422 --- /dev/null +++ b/host.json @@ -0,0 +1,23 @@ +{ + "version": "2.0", + "logging": { + "applicationInsights": { + "samplingSettings": { + "isEnabled": true, + "excludedTypes": "Request" + } + } + }, + "extensionBundle": { + "id": "Microsoft.Azure.Functions.ExtensionBundle", + "version": "[2.*, 3.0.0)" + }, + "customHandler": { + "description": { + "defaultExecutablePath": "handler", + "workingDirectory": "", + "arguments": [] + }, + "enableForwardingHttpRequest": true + } +} From 25000f81c17d7a5eb1eb84619f61aa5b3256c2ec Mon Sep 17 00:00:00 2001 From: Anish Sharma Date: Tue, 23 Nov 2021 17:30:50 +0530 Subject: [PATCH 2/3] reorganized files --- .gitignore | 12 ------------ .funcignore => AzureFunctions/.funcignore | 0 AzureFunctions/.gitignore | 13 +++++++++++++ .../HttpExample}/function.json | 0 host.json => AzureFunctions/host.json | 0 Makefile | 7 +++++++ handler.go => cmd/handler/main.go | 0 go.mod | 3 +++ 8 files changed, 23 insertions(+), 12 deletions(-) rename .funcignore => AzureFunctions/.funcignore (100%) create mode 100644 AzureFunctions/.gitignore rename {HttpExample => AzureFunctions/HttpExample}/function.json (100%) rename host.json => AzureFunctions/host.json (100%) create mode 100644 Makefile rename handler.go => cmd/handler/main.go (100%) create mode 100644 go.mod diff --git a/.gitignore b/.gitignore index 6bbc18e..7ce9bd3 100644 --- a/.gitignore +++ b/.gitignore @@ -1,15 +1,3 @@ - -# Azure Functions artifacts -bin -obj -appsettings.json -local.settings.json - -# Azurite artifacts -__blobstorage__ -__queuestorage__ -__azurite_db*__.json - # Go # Binaries for programs and plugins *.exe diff --git a/.funcignore b/AzureFunctions/.funcignore similarity index 100% rename from .funcignore rename to AzureFunctions/.funcignore diff --git a/AzureFunctions/.gitignore b/AzureFunctions/.gitignore new file mode 100644 index 0000000..8a91ef3 --- /dev/null +++ b/AzureFunctions/.gitignore @@ -0,0 +1,13 @@ +# Azure Functions artifacts +bin +obj +appsettings.json +local.settings.json + +# Azurite artifacts +__blobstorage__ +__queuestorage__ +__azurite_db*__.json + +# Handler Binary +handler \ No newline at end of file diff --git a/HttpExample/function.json b/AzureFunctions/HttpExample/function.json similarity index 100% rename from HttpExample/function.json rename to AzureFunctions/HttpExample/function.json diff --git a/host.json b/AzureFunctions/host.json similarity index 100% rename from host.json rename to AzureFunctions/host.json diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..1888de8 --- /dev/null +++ b/Makefile @@ -0,0 +1,7 @@ +all: AzureFunctions/handler + +AzureFunctions/handler: cmd/handler/main.go + CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags '-extldflags "-static"' -o $@ $< + +clean: + rm AzureFunctions/handler \ No newline at end of file diff --git a/handler.go b/cmd/handler/main.go similarity index 100% rename from handler.go rename to cmd/handler/main.go diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..c337316 --- /dev/null +++ b/go.mod @@ -0,0 +1,3 @@ +module github.com/SimplQ/simplQ-golang + +go 1.17 From 1cdffc4e1b29819e94237fb92ede0b62b43255f1 Mon Sep 17 00:00:00 2001 From: aneeshsharma Date: Tue, 23 Nov 2021 18:08:56 +0530 Subject: [PATCH 3/3] make file zips function for deployment --- .gitignore | 3 +++ Makefile | 5 ++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 7ce9bd3..9da0dec 100644 --- a/.gitignore +++ b/.gitignore @@ -12,5 +12,8 @@ # Output of the go coverage tool, specifically when used with LiteIDE *.out +# Build +build/ + # Dependency directories (remove the comment below to include it) # vendor/ \ No newline at end of file diff --git a/Makefile b/Makefile index 1888de8..abbe307 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,10 @@ all: AzureFunctions/handler + cd AzureFunctions && zip -r ../build/azure_functions.zip * + ls -lh build/azure_functions.zip AzureFunctions/handler: cmd/handler/main.go CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags '-extldflags "-static"' -o $@ $< clean: - rm AzureFunctions/handler \ No newline at end of file + rm AzureFunctions/handler + rm build/* \ No newline at end of file