Guest User

Untitled

a guest
Oct 19th, 2017
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. package main
  2.  
  3. import (
  4. "fmt"
  5. "http"
  6. "websocket"
  7. "time"
  8. )
  9.  
  10. func uiServer(s string) websocket.Handler {
  11. return func(ws *websocket.Conn) {
  12. fmt.Println(s)
  13. }
  14. }
  15.  
  16. func detector(quit chan bool) {
  17. for {
  18. select {
  19. case <- quit:
  20. fmt.Println("bailing")
  21. default:
  22. time.Sleep(100000)
  23. }
  24. }
  25. }
  26.  
  27. func main() {
  28. quit := make(chan bool)
  29. go detector(quit)
  30.  
  31. http.Handle("/daemon", websocket.Handler(uiServer("test")))
  32. err := http.ListenAndServe(":7070", nil)
  33. if err != nil {
  34. fmt.Println("Failed to open ", err)
  35. }
  36. time.Sleep(1) // stupid unsed imports
  37. }
Add Comment
Please, Sign In to add comment