Commit 9e592b56 by CalciumIon

fix: try to fix panic #369

parent 5f137378
...@@ -5,6 +5,7 @@ import ( ...@@ -5,6 +5,7 @@ import (
"errors" "errors"
"fmt" "fmt"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"net/http"
"one-api/common" "one-api/common"
) )
...@@ -20,10 +21,10 @@ func StringData(c *gin.Context, str string) error { ...@@ -20,10 +21,10 @@ func StringData(c *gin.Context, str string) error {
//str = strings.TrimPrefix(str, "data: ") //str = strings.TrimPrefix(str, "data: ")
//str = strings.TrimSuffix(str, "\r") //str = strings.TrimSuffix(str, "\r")
c.Render(-1, common.CustomEvent{Data: "data: " + str}) c.Render(-1, common.CustomEvent{Data: "data: " + str})
if c.Writer != nil { if flusher, ok := c.Writer.(http.Flusher); ok {
c.Writer.Flush() flusher.Flush()
} else { } else {
return errors.New("writer is nil") return errors.New("streaming error: flusher not found")
} }
return nil return nil
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment