2026-04-01 17:31:45 +00:00
|
|
|
// SPDX-License-Identifier: EUPL-1.2
|
|
|
|
|
|
|
|
|
|
package api
|
|
|
|
|
|
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
|
|
|
import (
|
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
|
|
core "dappco.re/go/core"
|
|
|
|
|
)
|
2026-04-01 17:31:45 +00:00
|
|
|
|
|
|
|
|
// normaliseServers trims whitespace, removes empty entries, and preserves
|
|
|
|
|
// the first occurrence of each server URL.
|
|
|
|
|
func normaliseServers(servers []string) []string {
|
|
|
|
|
if len(servers) == 0 {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cleaned := make([]string, 0, len(servers))
|
|
|
|
|
seen := make(map[string]struct{}, len(servers))
|
|
|
|
|
|
|
|
|
|
for _, server := range servers {
|
2026-04-01 20:01:34 +00:00
|
|
|
server = normaliseServer(server)
|
2026-04-01 17:31:45 +00:00
|
|
|
if server == "" {
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
if _, ok := seen[server]; ok {
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
seen[server] = struct{}{}
|
|
|
|
|
cleaned = append(cleaned, server)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if len(cleaned) == 0 {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return cleaned
|
|
|
|
|
}
|
2026-04-01 20:01:34 +00:00
|
|
|
|
|
|
|
|
// normaliseServer trims surrounding whitespace and removes a trailing slash
|
|
|
|
|
// from non-root server URLs so equivalent metadata collapses to one entry.
|
|
|
|
|
func normaliseServer(server 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
|
|
|
server = core.Trim(server)
|
2026-04-01 20:01:34 +00:00
|
|
|
if server == "" {
|
|
|
|
|
return ""
|
|
|
|
|
}
|
|
|
|
|
if server == "/" {
|
|
|
|
|
return server
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
server = strings.TrimRight(server, "/")
|
|
|
|
|
if server == "" {
|
|
|
|
|
return "/"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return server
|
|
|
|
|
}
|