Split code in respective files.

Resource method name change.

Route list func
This commit is contained in:
2025-08-16 11:19:45 +05:30
parent f91090b35e
commit 855b82e9df
10 changed files with 506 additions and 366 deletions

51
route.go Normal file
View File

@@ -0,0 +1,51 @@
package mux
import (
"fmt"
"log/slog"
"sync"
)
type RouteList struct {
mu sync.RWMutex
routes []string
}
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) {
return "0", 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()
return s.routes
}