This commit is contained in:
cdle
2023-06-27 13:27:04 +08:00
parent 564ced7f4f
commit 3bdbb07ba3
11 changed files with 194 additions and 12 deletions
+13
View File
@@ -8,6 +8,7 @@ import (
"github.com/dop251/goja"
"github.com/gin-gonic/gin"
"github.com/goccy/go-json"
"github.com/gorilla/websocket"
)
type Response struct {
@@ -26,9 +27,11 @@ type Response struct {
isJson bool
status int
isRedirect bool
conn *websocket.Conn
}
func (r *Response) Send(gv goja.Value) *Response {
gve := gv.Export()
switch gve := gve.(type) {
case string:
@@ -42,6 +45,11 @@ func (r *Response) Send(gv goja.Value) *Response {
r.content += fmt.Sprint(gve)
}
}
if r.conn != nil {
r.conn.WriteMessage(1, []byte(r.content))
r.content = ""
return r
}
return r
}
@@ -68,6 +76,11 @@ func (r *Response) Json(ps ...interface{}) *Response {
} else {
r.content += fmt.Sprint(data)
}
if r.conn != nil {
r.conn.WriteMessage(1, d)
r.content = ""
return r
}
return r
}