mirror of
				https://github.com/linux-do/new-api.git
				synced 2025-11-04 13:23:42 +08:00 
			
		
		
		
	fix: try to fix panic #369
This commit is contained in:
		@@ -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 {
 | 
				
			|||||||
	//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
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user