I developed an api that only receives the POST method using the Golang (GO) language
when deploying the application through VSCode everything goes very well, and the api works locally along with my tests.
but when testing using the url that the azure function provides i get an error
error:
HTTP response code
500 Internal Server Error
i am very new to the programming world and also to the azure world so i will share my code to get some help
code go:
func main() {
dbload := Init()
h := OpenDB(dbload)
/*port := os.Getenv("HTTP_PLATFORM_PORT")
if port == "" {
port = "8080"
}*/
router := gin.Default()
router.POST("/webhook/sendgrid", h.sendgridWeb)
//router.GET("/ping", ping)
port := os.Getenv("HTTP_PLATFORM_PORT")
// default back to 8080 for local dev
if port == "" {
port = "8080"
}
router.Run("127.0.0.1:" + port)
}
functions.json:
{
"bindings": [
{
"authLevel": "anonymous",
"type": "httpTrigger",
"direction": "in",
"name": "req",
"methods": [
"get",
"post"
]
},
{
"type": "http",
"direction": "out",
"name": "res"
}
]
}
host.json:
{
"version": "2.0",
"logging": {
"applicationInsights": {
"samplingSettings": {
"isEnabled": true,
"excludedTypes": "Request"
}
}
},
"extensionBundle": {
"id": "Microsoft.Azure.Functions.ExtensionBundle",
"version": "[3.*, 4.0.0)"
},
"customHandler": {
"description": {
"defaultExecutablePath": "main.exe",
"workingDirectory": "",
"arguments": []
},
"enableForwardingHttpRequest": true
}
}
local.settings.json:
{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "",
"FUNCTIONS_WORKER_RUNTIME": "custom"
}
}
I did a test using the azure platform, inside my azure function I went to: functions -> name of my function ->> code+test ->> test/run
and I got the following error:
[Error] Executed 'Functions.webhook2' (Failed, Id=1322bd2d-5c9d-4b79-9424-2b29b53c2148, Duration=37ms)
I viewed the logs using Kudu, all the logs say:
2023-01-10T13:07:22.900 [Information] Executing 'Functions.webhook2' (Reason='This function was programmatically called via the host APIs.', Id=cdaa0875-9625-414f-86a9-f6dfab4f966a)
2023-01-10T13:07:22.980 [Error] Executed 'Functions.webhook2' (Failed, Id=cdaa0875-9625-414f-86a9-f6dfab4f966a, Duration=31ms)
An existing connection was forcibly closed by the remote host.
a diagnostic was also made to solve problems, but no error is returned