-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsiflolly.go
More file actions
71 lines (58 loc) · 1.75 KB
/
siflolly.go
File metadata and controls
71 lines (58 loc) · 1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package main
import (
// "html/template"
// "io/ioutil"
"fmt"
"github.com/gorilla/websocket"
"github.com/hlawrenz/siflolly/cacophony"
"github.com/hlawrenz/siflolly/noise"
"log"
"net/http"
"os"
"path"
)
type Context struct {
Title string
}
//var templates = template.Must(template.ParseFiles("index.html"))
func rootHandler(w http.ResponseWriter, r *http.Request) {
}
func echoHandler(w http.ResponseWriter, r *http.Request) {
conn, err := websocket.Upgrade(w, r, nil, 1024, 1024)
if _, ok := err.(websocket.HandshakeError); ok {
http.Error(w, "Not a websocket handshake", 400)
return
} else if err != nil {
log.Println(err)
return
}
log.Println("Past connection")
for {
messageType, p, err := conn.ReadMessage()
if err != nil {
return
}
log.Println(messageType)
log.Println(p)
if err = conn.WriteMessage(messageType, p); err != nil {
return
}
}
}
var assetDir = path.Join(os.Getenv("GOPATH"), "src/github.com/hlawrenz/siflolly/assets/")
var echowsDir = path.Join(os.Getenv("GOPATH"), "src/github.com/hlawrenz/siflolly/echows/")
var templateDir = path.Join(os.Getenv("GOPATH"), "src/github.com/hlawrenz/siflolly/templates/")
func main() {
http.Handle("/assets/", http.StripPrefix("/assets/", http.FileServer(http.Dir(assetDir))))
http.Handle("/echows/", http.StripPrefix("/echows/", http.FileServer(http.Dir(echowsDir))))
//http.Handle("/assets/", http.StripPrefix("/assets/", http.FileServer(http.Dir("./assets"))))
fmt.Println(assetDir)
http.HandleFunc("/echosock", echoHandler)
sb := noise.NewSwitchboard()
n := noise.Noise{Sb: &sb}
http.HandleFunc("/noise", n.ServeWs)
csb := cacophony.NewSwitchboard()
c := cacophony.Cacophony{Sb: &csb}
http.HandleFunc("/cacophony", c.ServeWs)
http.ListenAndServe(":8888", nil)
}