12.10 HTTP连接超时
package main
import (
"fmt"
"io"
"net"
"net/http"
"os"
"path/filepath"
"strconv"
"time"
)
var timeout = time.Duration(time.Second)func Timeout(network, host string) (net.Conn, error) {
conn, err := net.DialTimeout(network, host,timeout)
if err != nil {
return nil, err
}
conn.SetDeadline(time.Now().Add(timeout))
return conn, nil
}Last updated