怎么才能让一个go程序一直运行呢

cups_book · · 3839 次点击
xmge
欲戴王冠 必承其重
```go package main import ( "log" "net/http" "os" "time" ) // 检测百度接口 var myLog = log.New(os.Stdout,"[api 检测] ",log.Lmicroseconds) func main() { for { time.Sleep(5 * time.Second) resp,err := http.Get("http://www.baidu.com") if err != nil { myLog.Println("请求百度错误:",err) continue } if resp.StatusCode != 200 { myLog.Println("百度出现故障,code:",resp.StatusCode) continue } myLog.Println("百度运行正常") } } ```
#2
更多评论
把业务加到For 循环中
#1