Skip to content

Commit

Permalink
improves
Browse files Browse the repository at this point in the history
  • Loading branch information
mvrpl committed May 25, 2024
1 parent 3409e60 commit 9059051
Show file tree
Hide file tree
Showing 5 changed files with 106 additions and 1 deletion.
31 changes: 31 additions & 0 deletions .github/workflows/goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: goreleaser

on:
pull_request:
push:

jobs:
goreleaser:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.20'
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v5
with:
distribution: goreleaser
version: 'latest'
args: release --clean
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Upload assets
uses: actions/upload-artifact@v3
with:
name: myapp
path: myfolder/dist/*
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@ go.sum

*.pdf
speeds.db/
speedtest
speedtest
dist/
49 changes: 49 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# This is an example .goreleaser.yml file with some sensible defaults.
# Make sure to check the documentation at https://goreleaser.com

# The lines below are called `modelines`. See `:help modeline`
# Feel free to remove those if you don't want/need to use them.
# yaml-language-server: $schema=https://goreleaser.com/static/schema.json
# vim: set ts=2 sw=2 tw=0 fo=cnqoj

version: 1

before:
hooks:
# You may remove this if you don't use go modules.
- go mod tidy
# you may remove this if you don't need go generate
- go generate ./...

builds:
- env:
- CGO_ENABLED=0
goos:
- linux
- windows
- darwin
goarch:
- amd64
- arm64

archives:
- format: tar.gz
# this name template makes the OS and Arch compatible with the results of `uname`.
name_template: >-
{{ .ProjectName }}_
{{- title .Os }}_
{{- if eq .Arch "amd64" }}x86_64
{{- else if eq .Arch "386" }}i386
{{- else }}{{ .Arch }}{{ end }}
{{- if .Arm }}v{{ .Arm }}{{ end }}
# use zip for windows archives
format_overrides:
- goos: windows
format: zip

changelog:
sort: asc
filters:
exclude:
- "^docs:"
- "^test:"
4 changes: 4 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ go 1.20
require (
github.com/dustin/go-humanize v1.0.1
github.com/goodsign/monday v1.0.1
github.com/jedib0t/go-pretty/v6 v6.5.9
github.com/showwin/speedtest-go v1.6.3
github.com/syndtr/goleveldb v1.0.0
github.com/urfave/cli/v2 v2.25.7
Expand All @@ -15,13 +16,16 @@ require (
require (
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db // indirect
github.com/mattn/go-runewidth v0.0.15 // indirect
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 // indirect
github.com/richardlehane/mscfb v1.0.4 // indirect
github.com/richardlehane/msoleps v1.0.3 // indirect
github.com/rivo/uniseg v0.2.0 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect
github.com/xuri/efp v0.0.0-20220603152613-6918739fd470 // indirect
github.com/xuri/nfp v0.0.0-20220409054826-5e722a1d9e22 // indirect
golang.org/x/crypto v0.8.0 // indirect
golang.org/x/net v0.9.0 // indirect
golang.org/x/sys v0.17.0 // indirect
)
20 changes: 20 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,24 @@ package main
import (
"encoding/json"
"errors"
"fmt"
"os"
"time"

ptable "github.com/jedib0t/go-pretty/v6/table"
"github.com/showwin/speedtest-go/speedtest"
"github.com/syndtr/goleveldb/leveldb"
"github.com/urfave/cli/v2"
)

func mapSlice[T any, M any](a []T, f func(T) M) []M {
n := make([]M, len(a))
for i, e := range a {
n[i] = f(e)
}
return n
}

func RunSpeedTest() {
var speedtestClient = speedtest.New()

Expand All @@ -33,6 +43,16 @@ func RunSpeedTest() {
Resultados: results,
}

t := ptable.NewWriter()
t.SetOutputMirror(os.Stdout)
t.AppendHeader(ptable.Row{"Server", "Cidade", "Distancia", "Latencia", "Jitter", "Velocidade Download", "Velocidade Upload", "Duracao Teste"})
t.AppendRows(mapSlice(result.Resultados, func(s speedtest.Server) ptable.Row {
downloadSpeed := fmt.Sprintf("%.0f Mbps", s.DLSpeed)
uploadSpeed := fmt.Sprintf("%.0f Mbps", s.ULSpeed)
return ptable.Row{s.Sponsor, s.Name, s.Distance, s.Latency, s.Jitter, downloadSpeed, uploadSpeed, s.TestDuration.Total}
}))
t.Render()

jsonStr, err := json.Marshal(result)
if err != nil {
panic(err)
Expand Down

0 comments on commit 9059051

Please sign in to comment.