diff options
author | Christian Pointner <equinox@spreadspace.org> | 2019-02-13 22:51:18 +0100 |
---|---|---|
committer | Christian Pointner <equinox@spreadspace.org> | 2019-02-13 22:51:28 +0100 |
commit | 9f81f0c1b6f24246e2ce60ce9bde5a92e7b7451a (patch) | |
tree | 1da382ac1722b96eafd3aa95cdfebcb89bb6091f /cmd/dolmetschctld/web.go | |
parent | added state change subscription to state machine (diff) |
move common types to own package
Diffstat (limited to 'cmd/dolmetschctld/web.go')
-rw-r--r-- | cmd/dolmetschctld/web.go | 23 |
1 files changed, 5 insertions, 18 deletions
diff --git a/cmd/dolmetschctld/web.go b/cmd/dolmetschctld/web.go index 696169f..6ffcfea 100644 --- a/cmd/dolmetschctld/web.go +++ b/cmd/dolmetschctld/web.go @@ -26,6 +26,8 @@ import ( "encoding/json" "net/http" "time" + + "spreadspace.org/dolmetschctl/pkg/types" ) type WebInterface struct { @@ -48,17 +50,8 @@ func webSendResponse(w http.ResponseWriter, status int, respdata interface{}) { encoder.Encode(respdata) } -type webError struct { - ResponseCode int `json:"response-code"` - Error string `json:"error"` -} - func webSendErrorResponse(w http.ResponseWriter, status int, error string) { - webSendResponse(w, status, webError{ResponseCode: status, Error: error}) -} - -type webLanguage struct { - Lang Language `json:"language"` + webSendResponse(w, status, types.WebError{ResponseCode: status, Error: error}) } func webLanguageHandler(sm *StateMachine, w http.ResponseWriter, r *http.Request) { @@ -67,7 +60,7 @@ func webLanguageHandler(sm *StateMachine, w http.ResponseWriter, r *http.Request return } - var result webLanguage + var result types.WebLanguage dec := json.NewDecoder(r.Body) dec.DisallowUnknownFields() if err := dec.Decode(&result); err != nil { @@ -82,19 +75,13 @@ func webLanguageHandler(sm *StateMachine, w http.ResponseWriter, r *http.Request webSendResponse(w, http.StatusOK, result) } -type webState struct { - State State `json:"state"` - Ratio float32 `json:"original-to-interpreter-ratio"` - Lang Language `json:"language"` -} - func webStateHandler(sm *StateMachine, w http.ResponseWriter, r *http.Request) { if r.Method != "GET" { webSendErrorResponse(w, http.StatusMethodNotAllowed, "only GET method is allowed") return } - var result webState + var result types.WebState result.State, result.Ratio, result.Lang = sm.GetState() webSendResponse(w, http.StatusOK, result) } |