If a function returns a string, just display it
This commit is contained in:
parent
c2d26b6053
commit
77fcaa39ff
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue