golang every 10 seconds to access the URL

package main
import (
    "fmt"
    "io/ioutil"
    "net/http"
    "time"
)

func main() {
    for true{
        getUrl();
        time.Sleep(time.Duration(10)*time.Second)
    }
    

}

func getUrl(){
    url := "https://www.pang.com/api/xx"
    req, _ := http.NewRequest("GET", url, nil)
    res, _ := http.DefaultClient.Do(req)
    defer res.Body.Close()
    body, _ := ioutil.ReadAll(res.Body)
    fmt.Println(string(body))
}
 
 
----------------------
reference:

golang post and get the transmission request  

http://www.361way.com/golang-post-get/5861.html
 
 

golang sleep

https://blog.csdn.net/lanyang123456/article/details/78158457

 
 

Guess you like

Origin www.cnblogs.com/pangchunyu/p/11388730.html