github.com/vertgenlab/gonomics@v1.0.0/fileio/http.go (about) 1 package fileio 2 3 import ( 4 "bufio" 5 "compress/gzip" 6 "fmt" 7 "net/http" 8 "strings" 9 10 "github.com/vertgenlab/gonomics/exception" 11 ) 12 13 // EasyHttp will fetch data from files uploaded to an internet server and stream data into EasyReader. 14 func EasyHttp(url string) *EasyReader { 15 answer := EasyReader{} 16 resp, err := http.Get(url) 17 exception.PanicOnErr(err) 18 if strings.HasSuffix(url, ".gz") { 19 answer.internalGzip, err = gzip.NewReader(resp.Body) 20 exception.PanicOnErr(err) 21 answer.BuffReader = bufio.NewReader(answer.internalGzip) 22 } else { 23 answer.BuffReader = bufio.NewReader(resp.Body) 24 answer.internalGzip = nil 25 } 26 return &answer 27 } 28 29 // CatUrl will process a url link and print it out to stdout. 30 func CatUrl(url string) string { 31 var answer string 32 reader := EasyOpen(url) 33 for i, done := EasyNextLine(reader); !done; i, done = EasyNextLine(reader) { 34 answer += fmt.Sprintf("%s\n", i) 35 } 36 return answer 37 }