Created
October 31, 2018 03:27
-
-
Save grepory/e36b96ae6f9a945aa869bac7d8aa511f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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