Web 开发实践 1
找一个比较简洁高星的源码来看看, web 的, 可以是 gin 框架的.
找一些偏向实践的资料:
- Go Web 开发: https://github.com/astaxie/build-web-application-with-golang/blob/master/zh/01.0.md
- Gin example: https://github.com/gin-gonic/examples.git
- Gin: https://github.com/gin-gonic/gin
监控网站状态
有监控网站运行状态的需求, 每隔多少秒就检查一次, 当状态异常时发送通知.
- 监控器: 负责拿网站固定页面的状态, 可以注册想观察的多个页面
调查
相关技术实现调查.
retry 方式获取页面内容
package main
import (
"fmt"
"github.com/hashicorp/go-retryablehttp"
"io/ioutil"
"time"
)
func main() {
client := retryablehttp.NewClient()
client.RetryWaitMax = 5 * time.Second
client.RetryMax = 2
url := "https://xxx.com"
resp, err := client.Get(url)
if err != nil {
panic(err)
}
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
panic(err)
}
fmt.Println("数据内容: ", string(body), "长度: ", len(body))
}