github.com/LagrangeDev/LagrangeGo@v0.0.0-20240512064304-ad4a85e10cb4/client/global.go (about) 1 package client 2 3 // from https://github.com/Mrs4s/MiraiGo/blob/master/client/global.go 4 5 import ( 6 "net" 7 "time" 8 9 "github.com/pkg/errors" 10 ) 11 12 func qualityTest(addr string) (int64, error) { 13 // see QualityTestManager 14 start := time.Now() 15 conn, err := net.DialTimeout("tcp", addr, time.Second*5) 16 if err != nil { 17 return 0, errors.Wrap(err, "failed to connect to server during quality test") 18 } 19 _ = conn.Close() 20 return time.Since(start).Milliseconds(), nil 21 }