Files
mux/route.go

54 lines
827 B
Go
Raw Permalink Normal View History

package mux
import (
"fmt"
"log/slog"
"sync"
)
type RouteList struct {
routes []string
mu sync.RWMutex
}
func (s *RouteList) Add(item string) {
if s == nil {
slog.Warn("failed on Add, RouteList is nil")
return
}
s.mu.Lock()
defer s.mu.Unlock()
s.routes = append(s.routes, item)
}
func (s *RouteList) Get(index int) (string, error) {
if s == nil {
slog.Warn("failed on Get, RouteList is nil")
return "", nil
}
s.mu.RLock()
defer s.mu.RUnlock()
if index < 0 || index >= len(s.routes) {
2026-02-20 17:05:34 +05:30
return "", fmt.Errorf("index out of bounds")
}
return s.routes[index], nil
}
func (s *RouteList) All() []string {
if s == nil {
slog.Warn("failed on All, RouteList is nil")
return nil
}
s.mu.RLock()
defer s.mu.RUnlock()
2026-02-20 17:05:34 +05:30
out := make([]string, len(s.routes))
copy(out, s.routes)
return out
}