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
1 changed files with 26 additions and 3 deletions

29
main.go
View File

@ -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()
}