This repository has been archived on 2022-09-04. You can view files and clone it, but cannot push or open issues or pull requests.
dataupdater/cron/helpers.go
2020-06-01 21:05:33 +02:00

30 lines
602 B
Go

package cron
import (
"compress/gzip"
"encoding/csv"
"io"
"net/http"
)
func uncompressAndGetCsvLines(r io.Reader) ([][]string, error) {
uncompressedStream, err := gzip.NewReader(r)
if err != nil {
return [][]string{}, err
}
defer uncompressedStream.Close()
return csv.NewReader(uncompressedStream).ReadAll()
}
func getCSVData(url string, compressed bool) ([][]string, error) {
resp, err := http.Get(url)
if err != nil {
return [][]string{}, nil
}
defer resp.Body.Close()
if !compressed {
return csv.NewReader(resp.Body).ReadAll()
}
return uncompressAndGetCsvLines(resp.Body)
}