-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
44 lines (35 loc) · 980 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
38
39
40
41
42
43
package main
import (
"flag"
"net/http"
"fmt"
"log"
"github.com/go-read-a-book/web"
"github.com/go-read-a-book/read"
)
//configurable ports
var tport = flag.Int("tport", 5555, "Listening port for text parsing")
var wport = flag.Int("wport", 8080, "Port for Restfull API refering to it as webport in code")
func init() {
//parse flags
flag.Parse()
}
func main() {
//start in goroutine to allow multiple instead of getting stuck at the first
//port to post data to
go SetTextPort()
//port to get stats from
SetWebPort()
}
func SetTextPort() {
http.HandleFunc("/", read.WordsAndChars)
txtPort := fmt.Sprint(":" , *tport);
fmt.Println("textReadingPort = " + txtPort)
log.Fatal(http.ListenAndServe(txtPort, nil))
}
func SetWebPort() {
http.HandleFunc("/stats", web.Stats)
webPort := fmt.Sprint(":" , *wport);
fmt.Println("Webport = " + webPort)
log.Fatal(http.ListenAndServe(webPort, nil))
}