librespeed / speedtest-cli

Command line client for LibreSpeed
GNU Lesser General Public License v3.0
485 stars 59 forks source link

Improved reports #63

Open czechbol opened 1 year ago

czechbol commented 1 year ago

Waiting until #62 is merged

I have improved the report structs. This way there is no need to differentiate between json and csv output formats until all the way at the end when printing the output.

I also replaced the os.Stdout.Write with fmt.Print and fmt.Println as it also writes to Stdout, the json output wasn't properly terminated (no newline char at the end) and this way the number of imports was reduced. It's also easier to use and doesn't change the behavior.

35 is unaffected, it works fine, no extra newlines are added (same with when on master without this PR)

speedtest-cli ❯ go run main.go --verbose --json > result.json 2> result.log
speedtest-cli ❯  go run main.go --csv-header
Timestamp,Server Name,Address,Ping,Jitter,Download,Upload,Share,IP
speedtest-cli ❯ cat result.json | jq
[
  {
    "timestamp": "2023-04-09T13:30:39.251614354+02:00",
    "server": {
      "name": "Virginia, United States, OVH",
      "url": "https://speed.riverside.rocks/"
    },
    "client": {
      "ip": "",
      "hostname": "",
      "city": "",
      "region": "",
      "country": "",
      "loc": "",
      "org": "",
      "postal": "",
      "timezone": ""
    },
    "bytes_sent": 189792256,
    "bytes_received": 182674200,
    "ping": 7,
    "jitter": 0.27,
    "upload": 97.32,
    "download": 93.67,
    "share": ""
  }
]
speedtest-cli ❯ tail result.log
Sponsored by: Riverside Rocks @ https://riverside.rocks
Failed when parsing get IP result: json: cannot unmarshal string into Go struct field GetIPResult.rawIspInfo of type defs.IPInfoResponse
Received payload: {"processedString":"2001:470:6e:1c2::2 - Unknown ISP","rawIspInfo":""}
You're testing from: {"processedString":"2001:470:6e:1c2::2 - Unknown ISP","rawIspInfo":""}
Failed when reading HTTP response: context deadline exceeded (Client.Timeout or context cancellation while reading body)
Failed when reading HTTP response: context deadline exceeded (Client.Timeout or context cancellation while reading body)
Failed when reading HTTP response: context deadline exceeded (Client.Timeout or context cancellation while reading body)
Failed when making HTTP request: Post "https://speed.riverside.rocks/empty.php": context deadline exceeded (Client.Timeout exceeded while awaiting headers)
Failed when making HTTP request: Post "https://speed.riverside.rocks/empty.php": context deadline exceeded (Client.Timeout exceeded while awaiting headers)
Failed when making HTTP request: Post "https://speed.riverside.rocks/empty.php": context deadline exceeded (Client.Timeout exceeded while awaiting headers)