If a function returns a string, just display it

This commit is contained in:
nemunaire 2016-01-13 13:22:03 +01:00
parent c2d26b6053
commit 77fcaa39ff
1 changed files with 5 additions and 1 deletions

View File

@ -4,6 +4,7 @@ import (
"encoding/json"
"errors"
"fmt"
"io"
"log"
"net/http"
"strings"
@ -82,7 +83,10 @@ func (a apiRouting) ServeHTTP(w http.ResponseWriter, r *http.Request) {
resStatus = http.StatusNotFound
}
if j, err := json.Marshal(ret); err != nil {
if str, found := ret.(string); found {
w.WriteHeader(resStatus)
io.WriteString(w, str)
} else if j, err := json.Marshal(ret); err != nil {
http.Error(w, fmt.Sprintf("{errmsg:\"%q\"}", err), http.StatusInternalServerError)
} else {
w.WriteHeader(resStatus)