mirror of
https://github.com/yusing/godoxy.git
synced 2026-04-23 08:48:32 +02:00
refactor(websocket): simplify NewManagerWithUpgrade function to use context for custom upgrader
This commit is contained in:
@@ -73,12 +73,12 @@ const (
|
|||||||
// NewManagerWithUpgrade upgrades the HTTP connection to a WebSocket connection and returns a Manager.
|
// NewManagerWithUpgrade upgrades the HTTP connection to a WebSocket connection and returns a Manager.
|
||||||
// If the upgrade fails, the error is returned.
|
// If the upgrade fails, the error is returned.
|
||||||
// If the upgrade succeeds, the Manager is returned.
|
// If the upgrade succeeds, the Manager is returned.
|
||||||
func NewManagerWithUpgrade(c *gin.Context, upgrader ...websocket.Upgrader) (*Manager, error) {
|
//
|
||||||
var actualUpgrader websocket.Upgrader
|
// To use a custom upgrader, set the "upgrader" context value to the upgrader.
|
||||||
if len(upgrader) == 0 {
|
func NewManagerWithUpgrade(c *gin.Context) (*Manager, error) {
|
||||||
actualUpgrader = defaultUpgrader
|
actualUpgrader := &defaultUpgrader
|
||||||
} else {
|
if upgrader, ok := c.Get("upgrader"); ok {
|
||||||
actualUpgrader = upgrader[0]
|
actualUpgrader = upgrader.(*websocket.Upgrader)
|
||||||
}
|
}
|
||||||
|
|
||||||
conn, err := actualUpgrader.Upgrade(c.Writer, c.Request, nil)
|
conn, err := actualUpgrader.Upgrade(c.Writer, c.Request, nil)
|
||||||
|
|||||||
Reference in New Issue
Block a user