2026-03-14 10:03:29 +00:00
|
|
|
// SPDX-License-Identifier: EUPL-1.2
|
|
|
|
|
|
|
|
|
|
package api
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"net/http"
|
2026-04-02 03:21:28 +00:00
|
|
|
"strings"
|
2026-03-14 10:03:29 +00:00
|
|
|
|
refactor: AX compliance sweep — replace banned stdlib imports with core primitives
Replaced fmt, strings, sort, os, io, sync, encoding/json, path/filepath,
errors, log, reflect with core.Sprintf, core.E, core.Contains, core.Trim,
core.Split, core.Join, core.JoinPath, slices.Sort, c.Fs(), c.Lock(),
core.JSONMarshal, core.ReadAll and other CoreGO v0.8.0 primitives.
Framework boundary exceptions preserved where stdlib types are required
by external interfaces (Gin, net/http, CGo, Wails, bubbletea).
Co-Authored-By: Virgil <virgil@lethean.io>
2026-04-13 09:32:00 +01:00
|
|
|
core "dappco.re/go/core"
|
|
|
|
|
|
2026-03-14 10:03:29 +00:00
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
|
)
|
|
|
|
|
|
2026-04-02 03:21:28 +00:00
|
|
|
// defaultWSPath is the URL path where the WebSocket endpoint is mounted.
|
|
|
|
|
const defaultWSPath = "/ws"
|
|
|
|
|
|
|
|
|
|
// wrapWSHandler adapts a standard http.Handler to a Gin handler for the WebSocket route.
|
2026-03-14 10:03:29 +00:00
|
|
|
// The underlying handler is responsible for upgrading the connection to WebSocket.
|
|
|
|
|
func wrapWSHandler(h http.Handler) gin.HandlerFunc {
|
|
|
|
|
return func(c *gin.Context) {
|
|
|
|
|
h.ServeHTTP(c.Writer, c.Request)
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-04-02 03:21:28 +00:00
|
|
|
|
|
|
|
|
// normaliseWSPath coerces custom WebSocket paths into a stable form.
|
|
|
|
|
// The path always begins with a single slash and never ends with one.
|
|
|
|
|
func normaliseWSPath(path string) string {
|
refactor: AX compliance sweep — replace banned stdlib imports with core primitives
Replaced fmt, strings, sort, os, io, sync, encoding/json, path/filepath,
errors, log, reflect with core.Sprintf, core.E, core.Contains, core.Trim,
core.Split, core.Join, core.JoinPath, slices.Sort, c.Fs(), c.Lock(),
core.JSONMarshal, core.ReadAll and other CoreGO v0.8.0 primitives.
Framework boundary exceptions preserved where stdlib types are required
by external interfaces (Gin, net/http, CGo, Wails, bubbletea).
Co-Authored-By: Virgil <virgil@lethean.io>
2026-04-13 09:32:00 +01:00
|
|
|
path = core.Trim(path)
|
2026-04-02 03:21:28 +00:00
|
|
|
if path == "" {
|
|
|
|
|
return defaultWSPath
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
path = "/" + strings.Trim(path, "/")
|
|
|
|
|
if path == "/" {
|
|
|
|
|
return defaultWSPath
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return path
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// resolveWSPath returns the configured WebSocket path or the default path
|
|
|
|
|
// when no override has been provided.
|
|
|
|
|
func resolveWSPath(path string) string {
|
refactor: AX compliance sweep — replace banned stdlib imports with core primitives
Replaced fmt, strings, sort, os, io, sync, encoding/json, path/filepath,
errors, log, reflect with core.Sprintf, core.E, core.Contains, core.Trim,
core.Split, core.Join, core.JoinPath, slices.Sort, c.Fs(), c.Lock(),
core.JSONMarshal, core.ReadAll and other CoreGO v0.8.0 primitives.
Framework boundary exceptions preserved where stdlib types are required
by external interfaces (Gin, net/http, CGo, Wails, bubbletea).
Co-Authored-By: Virgil <virgil@lethean.io>
2026-04-13 09:32:00 +01:00
|
|
|
if core.Trim(path) == "" {
|
2026-04-02 03:21:28 +00:00
|
|
|
return defaultWSPath
|
|
|
|
|
}
|
|
|
|
|
return normaliseWSPath(path)
|
|
|
|
|
}
|