社区微信群开通啦,扫一扫抢先加入社区官方微信群
社区微信群
使用腾讯云的Serverless服务,部署一个Go编写的天气变化的提醒应用
该应用通过定时查询高德地图的天气API,当当前天气或未来几天天气不好时,通过Server酱在微信中进行提醒
应用使用 go modules开发
module weather
go 1.12
require github.com/tencentyun/scf-go-lib v0.0.0-20190817080819-4a2819cda320
package main
import (
"log"
"os"
"strconv"
"time"
"fmt"
"github.com/tencentyun/scf-go-lib/cloudfunction"
"weather/tool"
)
func main() {
cloudfunction.Start(checkWeather)
}
func checkWeather() (string, error) {
// ...
}
在腾讯云的Serverless服务中创建新的函数
配置共三项:
在函数配置点击编辑,添加环境变量
city xxxx
weatherKey xxxx
notifyKey xxxx
GOOS=linux GOARCH=amd64 go build -o main main.go
zip main.zip main
set GOOS=linux
set GOARCH=amd64
go build -o main main.go
然后将main添加到压缩文件中
在函数代码中上传压缩文件,保存
待上传完成后,选择 HelloWorld测试模板,点击测试,等函数执行,会看到测试结果
在触发方式中添加定时触发,cron表达式为 0 30 8-21 * * * *
,这样就可以在每天8点-21点的30分触发查询,如果天气状况不佳,会通过微信通知
如果觉得我的文章对您有用,请随意打赏。你的支持将鼓励我继续创作!