If a function returns a string, just display it
This commit is contained in:
parent
c2d26b6053
commit
77fcaa39ff
1 changed files with 5 additions and 1 deletions
|
|
@ -4,6 +4,7 @@ import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
@ -82,7 +83,10 @@ func (a apiRouting) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
resStatus = http.StatusNotFound
|
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)
|
http.Error(w, fmt.Sprintf("{errmsg:\"%q\"}", err), http.StatusInternalServerError)
|
||||||
} else {
|
} else {
|
||||||
w.WriteHeader(resStatus)
|
w.WriteHeader(resStatus)
|
||||||
|
|
|
||||||
Reference in a new issue