got it to work and log to web, next step, tcp
This commit is contained in:
parent
7f6b58b0b1
commit
b567834227
29
main.go
29
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()
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user