Skip to content

Instantly share code, notes, and snippets.

@grepory
Created October 31, 2018 03:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save grepory/e36b96ae6f9a945aa869bac7d8aa511f to your computer and use it in GitHub Desktop.
Save grepory/e36b96ae6f9a945aa869bac7d8aa511f to your computer and use it in GitHub Desktop.
package main
import (
"bufio"
"flag"
"io/ioutil"
"log"
"net/http"
"strings"
"time"
)
var yourBook = flag.String("book", "mobydick.txt", "path to your book")
func handler(book string) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
flusher, _ := w.(http.Flusher)
scanner := bufio.NewScanner(strings.NewReader(book))
scanner.Split(bufio.ScanLines)
for scanner.Scan() {
if _, err := w.Write(scanner.Bytes()); err != nil {
return
}
if _, err := w.Write([]byte("\n")); err != nil {
return
}
flusher.Flush()
time.Sleep(24 * time.Hour)
}
return
}
}
func main() {
flag.Parse()
urtext, err := ioutil.ReadFile(*yourBook)
if err != nil {
panic(err)
}
log.Fatal(http.ListenAndServe(":9000", handler(string(urtext))))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment