got it to work and log to web, next step, tcp

This commit is contained in:
Derek McQuay 2015-11-30 21:44:43 -08:00
parent 7f6b58b0b1
commit b567834227

29
main.go
View File

@ -3,6 +3,7 @@ package main
import ( import (
"fmt" "fmt"
"math/rand" "math/rand"
"net/http"
"sync" "sync"
"time" "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() { func init() {
rand.Seed(time.Now().UnixNano()) rand.Seed(time.Now().UnixNano())
} }
func main() { var q = queue{
q := queue{
size: 10, size: 10,
} }
func main() {
http.HandleFunc("/", handler)
go http.ListenAndServe(":8080", nil)
fmt.Println("here")
load(&q) load(&q)
printer(&q)
ch := work(&q) ch := work(&q)
for { for {
select { 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()
}