Golang timed request URL

Golang timed request URL

package main

import (
	"fmt"
	"net/http"
	"strings"
	"time"
)

func main() {
    
    

	t1 := time.NewTimer(time.Second * 30)
	t2 := time.NewTimer(time.Second * 60)
	for {
    
    
		select {
    
    

		case <-t1.C:
			POSTURL("https://test.cn/api/HandlePreOrderPrint")
			GETURL("https://test.cn/api/HandlePullOrderPrint")
			t1.Reset(time.Second * 30)

		case <-t2.C:
			POSTURL("https://test.cn/api/HandleUpdatePayStatus")
			t2.Reset(time.Second * 60)
	}
}
func POSTURL(api string) {
    
    
	http.Post(api, "", strings.NewReader("name=cron"))
	fmt.Println(string(api))
}
func GETURL(api string) {
    
    
	http.Get(api)
	fmt.Println(string(api))
}

Guess you like

Origin blog.csdn.net/lswzw/article/details/105391485