v0.1.1, Added SetJSON for content

This commit is contained in:
Eugeny Leonov 2022-07-07 18:32:11 +05:00
parent 3cc040b587
commit e1d894678c
2 changed files with 12 additions and 1 deletions

View File

@ -1,6 +1,7 @@
package httpsrv
import (
"encoding/json"
"fmt"
"net/http"
@ -92,6 +93,16 @@ func (r *Rec) Sent() {
r._sent = true
}
//Установить ответ в JSON
func (r *Rec) SetJSON(data interface{}) *Rec {
dta, e := json.Marshal(data)
if e != nil {
errs.RaiseError(ErrJSONError, e.Error())
dta = []byte("Error: " + e.Error())
}
return r.SetContent(dta)
}
//Установить тело ответа
func (r *Rec) SetContent(content []byte) *Rec {
r._content = content

View File

@ -1,3 +1,3 @@
package httpsrv
const Version = "0.1.0"
const Version = "0.1.1"