From b5678342279536b95ddbb597f3515cc0afb29db8 Mon Sep 17 00:00:00 2001 From: derek mcquay Date: Mon, 30 Nov 2015 21:44:43 -0800 Subject: [PATCH] got it to work and log to web, next step, tcp --- main.go | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/main.go b/main.go index 43dc4b4..11fe501 100644 --- a/main.go +++ b/main.go @@ -3,6 +3,7 @@ package main import ( "fmt" "math/rand" + "net/http" "sync" "time" ) @@ -52,15 +53,31 @@ func load(q *queue) { }() } +func printer(q *queue) { + go func() { + for { + mu.Lock() + fmt.Println(q) + mu.Unlock() + time.Sleep(time.Millisecond * 1000) + } + }() +} + func init() { rand.Seed(time.Now().UnixNano()) } +var q = queue{ + size: 10, +} + func main() { - q := queue{ - size: 10, - } + http.HandleFunc("/", handler) + go http.ListenAndServe(":8080", nil) + fmt.Println("here") load(&q) + printer(&q) ch := work(&q) for { select { @@ -69,3 +86,9 @@ func main() { } } } + +func handler(w http.ResponseWriter, req *http.Request) { + mu.Lock() + fmt.Fprintf(w, fmt.Sprintf("%v", q)) + mu.Unlock() +}