-
Notifications
You must be signed in to change notification settings - Fork 648
/
trace.go
43 lines (38 loc) 路 813 Bytes
/
trace.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package trace
import (
"fmt"
"github.com/spf13/cobra"
"io/ioutil"
"log"
"net/http"
"strings"
. "wgcf/cmd/util"
"wgcf/util"
)
var shortMsg = "Prints trace information about the current internet connection"
var Cmd = &cobra.Command{
Use: "trace",
Short: shortMsg,
Long: FormatMessage(shortMsg, `
Useful for verifying if Warp and Warp+ are working.`),
Run: func(cmd *cobra.Command, args []string) {
if err := trace(); err != nil {
log.Fatal(util.GetErrorMessage(err))
}
},
}
func init() {
}
func trace() error {
response, err := http.Get("https://cloudflare.com/cdn-cgi/trace")
if err != nil {
return err
}
bodyBytes, err := ioutil.ReadAll(response.Body)
if err != nil {
return err
}
log.Println("Trace result:")
fmt.Println(strings.TrimSpace(string(bodyBytes)))
return nil
}