Basic bidirectional WS server
- Fake temporary protocol (will probably be JSON RPC later) - Service can write freely to client through server - Any new component we need (workers, etc.) can access the channels to write to the client
This commit is contained in:
committed by
Brendan Le Glaunec
parent
4e922a2a48
commit
5a8417cf18
+19
-4
@@ -17,18 +17,33 @@ import (
|
||||
"net/http"
|
||||
"os"
|
||||
|
||||
"github.com/EtixLabs/cameradar/server/actor/pubsub"
|
||||
"github.com/EtixLabs/cameradar/server/actor/server"
|
||||
"github.com/EtixLabs/cameradar/server/adaptor/websocket"
|
||||
"github.com/EtixLabs/cameradar/server/service"
|
||||
graceful "gopkg.in/tylerb/graceful.v1"
|
||||
)
|
||||
|
||||
func main() {
|
||||
webSocketFactory := websocket.NewGorillaFactory()
|
||||
pubsub := pubsub.NewWebSocket(webSocketFactory)
|
||||
fromClient := make(chan string)
|
||||
toClient := make(chan string)
|
||||
|
||||
server := server.New(webSocketFactory, fromClient, toClient)
|
||||
|
||||
_, err := service.New(
|
||||
"/Users/ullaakut/Work/go/src/github.com/EtixLabs/cameradar/dictionaries/routes",
|
||||
"/Users/ullaakut/Work/go/src/github.com/EtixLabs/cameradar/dictionaries/credentials.json",
|
||||
fromClient,
|
||||
toClient,
|
||||
)
|
||||
if err != nil {
|
||||
fmt.Printf("could not start service: %v", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
// create and setup the http server
|
||||
serverMux := http.NewServeMux()
|
||||
serverMux.HandleFunc("/", pubsub.Accept)
|
||||
serverMux.HandleFunc("/", server.Accept)
|
||||
|
||||
httpServer := &graceful.Server{
|
||||
NoSignalHandling: true,
|
||||
@@ -39,7 +54,7 @@ func main() {
|
||||
}
|
||||
|
||||
fmt.Printf("cameradar server listening on %v\n", httpServer.Addr)
|
||||
err := httpServer.ListenAndServe()
|
||||
err = httpServer.ListenAndServe()
|
||||
if err != nil {
|
||||
fmt.Printf("could not start server: %v\n", err)
|
||||
os.Exit(1)
|
||||
|
||||
Reference in New Issue
Block a user