Skip to content

Commit

Permalink
refactor(main): cleanup, use internal/fast instead
Browse files Browse the repository at this point in the history
  • Loading branch information
adhocore committed Apr 3, 2021
1 parent a6803e9 commit 0252e6b
Showing 1 changed file with 2 additions and 46 deletions.
48 changes: 2 additions & 46 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,53 +1,9 @@
package main

import (
"context"
"fmt"
"log"
"time"

"github.com/chromedp/chromedp"
"github.com/chromedp/cdproto/emulation"
"github.com/adhocore/fast/internal/fast"
)

func main() {
ctx, cancel := chromedp.NewContext(
context.Background(),
chromedp.WithLogf(log.Printf),
)
defer cancel()

ctx, cancel = context.WithTimeout(ctx, 60*time.Second)
defer cancel()

start := time.Now()

var (
up string
dw string
upunit string
dwunit string
)

err := chromedp.Run(ctx,
emulation.SetUserAgentOverride(`chromedp/chromedp v0.6.10`),
chromedp.Navigate(`https://fast.com`),
chromedp.ScrollIntoView(`footer`),
chromedp.WaitVisible(`#speed-value.succeeded`),
chromedp.Text(`#speed-value.succeeded`, &dw, chromedp.NodeVisible, chromedp.ByQuery),
chromedp.Text(`#speed-units.succeeded`, &dwunit, chromedp.NodeVisible, chromedp.ByQuery),
chromedp.Click(`#show-more-details-link`),
chromedp.WaitVisible(`#upload-value.succeeded`),
chromedp.Text(`#upload-value.succeeded`, &up, chromedp.NodeVisible, chromedp.ByQuery),
chromedp.Text(`#upload-units.succeeded`, &upunit, chromedp.NodeVisible, chromedp.ByQuery),
)

if err != nil {
log.Fatal(err)
}

fmt.Printf("\033[36mdownload speed:\033[m \033[32m%s\033[m %s\n", dw, dwunit)
fmt.Printf("\033[36mupload speed:\033[m \033[31m%s\033[m %s\n", up, upunit)
fmt.Printf("\n")
fmt.Printf("\033[36m> took: \033[33m%f\033[m secs\n", time.Since(start).Seconds())
fast.Run()
}

0 comments on commit 0252e6b

Please sign in to comment.