API can respond directly []byte (like files)

This commit is contained in:
nemunaire 2016-01-20 19:54:27 +01:00
parent a1d60ee78f
commit 9324f6f5fa
1 changed files with 3 additions and 0 deletions

View File

@ -87,6 +87,9 @@ func (a apiRouting) ServeHTTP(w http.ResponseWriter, r *http.Request) {
if str, found := ret.(string); found {
w.WriteHeader(resStatus)
io.WriteString(w, str)
} else if bts, found := ret.([]byte); found {
w.WriteHeader(resStatus)
w.Write(bts)
} else if j, err := json.Marshal(ret); err != nil {
http.Error(w, fmt.Sprintf("{\"errmsg\":\"%q\"}", err), http.StatusInternalServerError)
} else {