diff --git a/dist/ttfb-go b/dist/ttfb-go index 2ab9c34..1d9c6f1 100755 Binary files a/dist/ttfb-go and b/dist/ttfb-go differ diff --git a/dist/ttfb-go_darwin_amd64 b/dist/ttfb-go_darwin_amd64 index 98f7ee6..84c6637 100755 Binary files a/dist/ttfb-go_darwin_amd64 and b/dist/ttfb-go_darwin_amd64 differ diff --git a/dist/ttfb-go_darwin_arm64 b/dist/ttfb-go_darwin_arm64 index aa90134..8859b9d 100755 Binary files a/dist/ttfb-go_darwin_arm64 and b/dist/ttfb-go_darwin_arm64 differ diff --git a/dist/ttfb-go_linux_arm b/dist/ttfb-go_linux_arm index aceb603..6f6f398 100755 Binary files a/dist/ttfb-go_linux_arm and b/dist/ttfb-go_linux_arm differ diff --git a/dist/ttfb-go_linux_arm64 b/dist/ttfb-go_linux_arm64 index 1947080..265bab8 100755 Binary files a/dist/ttfb-go_linux_arm64 and b/dist/ttfb-go_linux_arm64 differ diff --git a/dist/ttfb-go_linux_arm64_static b/dist/ttfb-go_linux_arm64_static index 37c48c6..051c754 100755 Binary files a/dist/ttfb-go_linux_arm64_static and b/dist/ttfb-go_linux_arm64_static differ diff --git a/dist/ttfb-go_linux_arm_static b/dist/ttfb-go_linux_arm_static index 2cc85d7..0345874 100755 Binary files a/dist/ttfb-go_linux_arm_static and b/dist/ttfb-go_linux_arm_static differ diff --git a/dist/ttfb-go_static b/dist/ttfb-go_static index 360dc11..9ec060c 100755 Binary files a/dist/ttfb-go_static and b/dist/ttfb-go_static differ diff --git a/main.go b/main.go index dc2819e..e98bd91 100644 --- a/main.go +++ b/main.go @@ -12,7 +12,7 @@ import ( ) // MeasureTTFB measures the Time to First Byte for the given URL. -func MeasureTTFB(url string, cookie string, verbose bool) (int64, error) { +func MeasureTTFB(url string, cookie string, verbose bool) (int64, int, error) { // Create a custom HTTP transport to allow measuring the TTFB. transport := &http.Transport{ TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, @@ -25,7 +25,7 @@ func MeasureTTFB(url string, cookie string, verbose bool) (int64, error) { // Create a new request. req, err := http.NewRequest("GET", url, nil) if err != nil { - return 0, err + return 0, 0, err } // If a cookie is provided, set it in the request header. @@ -46,7 +46,7 @@ func MeasureTTFB(url string, cookie string, verbose bool) (int64, error) { // Perform the request. resp, err := client.Do(req) if err != nil { - return 0, err + return 0, 0, err } defer resp.Body.Close() @@ -57,7 +57,7 @@ func MeasureTTFB(url string, cookie string, verbose bool) (int64, error) { fmt.Println("Received response status:", resp.Status) } - return ttfb, nil + return ttfb, resp.StatusCode, nil } func main() { @@ -86,17 +86,17 @@ func main() { } // Measure the TTFB. - ttfb, err := MeasureTTFB(url, cookie, *verbose) + ttfb, statusCode, err := MeasureTTFB(url, cookie, *verbose) if err != nil { fmt.Printf("Error measuring TTFB: %v\n", err) os.Exit(1) } - // Only print the TTFB in milliseconds by default. + // Print the TTFB and HTTP status code. if *verbose { - fmt.Printf("Time to First Byte for %s: %d ms\n", url, ttfb) + fmt.Printf("Time to First Byte for %s: %d ms, HTTP Status: %d\n", url, ttfb, statusCode) } else { - fmt.Printf("%d\n", ttfb) + fmt.Printf("%d,%d\n", ttfb, statusCode) } }