define result as interface{}

This way we can easily reset the result after we hit an error, which
then omits the result.
This commit is contained in:
Gibheer 2021-05-03 19:43:25 +02:00
parent 9e6a6fbe28
commit 8953b10faa
1 changed files with 4 additions and 3 deletions

View File

@ -50,9 +50,9 @@ type (
// Response can have messages and/or a result to return the to client. // Response can have messages and/or a result to return the to client.
Response struct { Response struct {
ID string `json:"id"` ID string `json:"id"`
Messages map[string][]string `json:"messages,omitempty"` Messages map[string][]string `json:"messages,omitempty"`
Result map[string]interface{} `json:"result,omitempty"` Result interface{} `json:"result,omitempty"`
} }
ident []byte ident []byte
@ -134,6 +134,7 @@ func (s *Server) Handle(w http.ResponseWriter, r *http.Request) {
} }
c.Logf(LevelInfo, "method '%s' called with '%s'", req.Method, req.Params) c.Logf(LevelInfo, "method '%s' called with '%s'", req.Method, req.Params)
if err := handler(c, req, res); err != nil { if err := handler(c, req, res); err != nil {
c.w.WriteHeader(http.StatusInternalServerError)
c.Logf(LevelError, "method '%s' returned an error: %s", req.Method, err) c.Logf(LevelError, "method '%s' returned an error: %s", req.Method, err)
} }
if err := tx.Commit(); err != nil { if err := tx.Commit(); err != nil {