mirror of
https://gitee.com/johng/gf
synced 2026-06-07 02:12:11 +08:00
ghttp.Response增加Writef、Writefln方法
This commit is contained in:
@ -13,6 +13,7 @@ import (
|
||||
"gitee.com/johng/gf/g/util/gconv"
|
||||
"gitee.com/johng/gf/g/encoding/gparser"
|
||||
"strconv"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
// 服务端请求返回对象
|
||||
@ -72,6 +73,11 @@ func (r *Response) Write(content ... interface{}) {
|
||||
r.mu.Unlock()
|
||||
}
|
||||
|
||||
// 返回信息,支持自定义format格式
|
||||
func (r *Response) Writef(format string, params ... interface{}) {
|
||||
r.Write(fmt.Sprintf(format, params...))
|
||||
}
|
||||
|
||||
// 返回信息,末尾增加换行标识符"\n"
|
||||
func (r *Response) Writeln(content ... interface{}) {
|
||||
if len(content) == 0 {
|
||||
@ -82,6 +88,11 @@ func (r *Response) Writeln(content ... interface{}) {
|
||||
r.Write(content...)
|
||||
}
|
||||
|
||||
// 返回信息,末尾增加换行标识符"\n"
|
||||
func (r *Response) Writefln(format string, params ... interface{}) {
|
||||
r.Writeln(fmt.Sprintf(format, params...))
|
||||
}
|
||||
|
||||
// 返回JSON
|
||||
func (r *Response) WriteJson(content interface{}) error {
|
||||
if b, err := gparser.VarToJson(content); err != nil {
|
||||
|
||||
Reference in New Issue
Block a user