added url fetching
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
package hmm
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// Lines returns a chan containing one line of output from the remote url.
|
||||
func Lines(url string) <-chan string {
|
||||
r := make(chan string)
|
||||
|
||||
go func() {
|
||||
defer close(r)
|
||||
resp, err := http.Get(url)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
s := bufio.NewScanner(resp.Body)
|
||||
for s.Scan() {
|
||||
r <- s.Text()
|
||||
}
|
||||
// ignore errors
|
||||
}()
|
||||
|
||||
return r
|
||||
}
|
||||
Reference in New Issue
Block a user