我有一个GO程序,当一个URL被击中时,它会以html格式提供波信息.它在带有nginx反向代理的虚拟机上运行.
我正在try 将代码移到AWS Lambda,但我正在努力理解如何触发和返回html.
原始代码完成了它的逻辑,并在下面的片段中以模板HTML的形式呈现了数据.
func indexHandler(w http.ResponseWriter, r *http.Request) {
GetWeather()
GetSurf()
CheckSurf(ForecastGroup)
p := CodCallPage{Title: "Swell Forecast", RunTime: htmlRunDate, DailyHtmlData: DailyMatchingSwells}
codcallTemplateInit.Execute(w, p)
}
func main() {
http.HandleFunc("/", indexHandler)
http.ListenAndServe(":8000", nil)
}
我相信我不再需要nginx代理,而需要调用lambda函数来运行我的代码.因此,我已将代码更改为以下代码.
func indexHandler(w http.ResponseWriter, r *http.Request) {
GetWeather()
GetSurf()
CheckSurf(ForecastGroup)
p := CodCallPage{Title: "Swell Forecast", RunTime: htmlRunDate, DailyHtmlData: DailyMatchingSwells}
codcallTemplateInit.Execute(w, p)
}
func handler(ctx context.Context, request events.APIGatewayProxyRequest) error {
log.Println("Via Lambda !!")
http.HandleFunc("/", indexHandler)
}
func main() {
lambda.Start(handler)
}
当我运行AWS测试时,Lamba函数使用默认的JSON文本.
{
"key1": "value1",
"key2": "value2",
"key3": "value3"
}
它在超时时会给出错误:
{
"errorMessage": "2023-06-08T08:43:13.714Z d6e2acc0-b1da-4e92-820b-63f8f5050947 Task timed out after 15.01 seconds"
}
我不确定是lambda函数忽略了测试,还是该函数没有以正确的方式返回HTML,或者lambda函数是否期望JSON而不是HTML?请问有什么建议可以帮助我理解,我应该看哪里?