go run xxx.go 只运行一次,进程就退出了啊
我想让一个go程序一直运行, 该怎么办?
目的是不停地去查一个api接口, 对返回的数值,进行检查
```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