-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
37 lines (28 loc) · 834 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package main
import (
"flag"
"fmt"
"log"
"net/http"
"github.com/eminano/markov"
)
func main() {
var n = flag.Uint("ngram", 3, "size of the ngrams to be processed when using learn")
var maxWords = flag.Uint("maxWords", 100, "max number of words on output when using generate")
var port = flag.Uint("port", 8080, "port for the server to listen on")
flag.Parse()
var ngramChain, err = markov.NewNGramChain(*n)
if err != nil {
log.Fatalf("error initialising text processor: %v", err)
}
h := Handlers{
processor: ngramChain,
maxWords: *maxWords,
}
http.HandleFunc("/learn", h.Learn)
http.HandleFunc("/generate", h.Generate)
log.Printf("Listening on localhost:%d", *port)
if err := http.ListenAndServe(fmt.Sprintf(":%d", *port), nil); err != nil {
log.Fatalf("error starting local server: %v", err)
}
}