Split code in respective files.
Resource method name change. Route list func
This commit is contained in:
51
route.go
Normal file
51
route.go
Normal 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
|
||||
}
|
Reference in New Issue
Block a user