summaryrefslogtreecommitdiff
path: root/cmd/dolmetschctld/web.go
diff options
context:
space:
mode:
authorChristian Pointner <equinox@spreadspace.org>2019-02-13 18:10:54 +0100
committerChristian Pointner <equinox@spreadspace.org>2019-02-13 18:10:54 +0100
commit6fc90db16480abee1b6aa3ee4352793054f99714 (patch)
tree5f43b8018e33457b1f556097c16704930d12255c /cmd/dolmetschctld/web.go
parentadded web handler for language (diff)
added basic web socket interface
Diffstat (limited to 'cmd/dolmetschctld/web.go')
-rw-r--r--cmd/dolmetschctld/web.go11
1 files changed, 7 insertions, 4 deletions
diff --git a/cmd/dolmetschctld/web.go b/cmd/dolmetschctld/web.go
index ade1e82..696169f 100644
--- a/cmd/dolmetschctld/web.go
+++ b/cmd/dolmetschctld/web.go
@@ -24,7 +24,6 @@ package main
import (
"encoding/json"
- "log"
"net/http"
"time"
)
@@ -76,8 +75,6 @@ func webLanguageHandler(sm *StateMachine, w http.ResponseWriter, r *http.Request
return
}
- log.Printf("web: got request %v", result)
-
if err := sm.SetLanguage(result.Lang); err != nil {
webSendErrorResponse(w, http.StatusBadRequest, err.Error())
return
@@ -106,12 +103,18 @@ func (web *WebInterface) Run() error {
return web.server.ListenAndServe()
}
-func NewWebInterface(addr string, sm *StateMachine) (web *WebInterface, err error) {
+func NewWebInterface(addr, staticDir string, sm *StateMachine) (web *WebInterface, err error) {
web = &WebInterface{}
+ if staticDir != "" {
+ http.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir(staticDir))))
+ }
+
http.Handle("/api/v1/state", webHandler{sm, webStateHandler})
http.Handle("/api/v1/language", webHandler{sm, webLanguageHandler})
+ http.Handle("/api/v1/socket", webHandler{sm, webSocketHandler})
+
web.server = &http.Server{Addr: addr, ReadTimeout: 2 * time.Hour, WriteTimeout: 2 * time.Hour}
return
}