the updated dependencies bring gocsv.MarshalStringWithoutHeaders which I depend on here
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)
Waiting until #62 is merged
gocsv.MarshalStringWithoutHeaders
which I depend on hereI 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
withfmt.Print
andfmt.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)