2025-08-16 11:19:45 +05:30
|
|
|
package mux
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"fmt"
|
|
|
|
|
"log/slog"
|
|
|
|
|
"sync"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type RouteList struct {
|
|
|
|
|
routes []string
|
feat: improve resource routing API and add comprehensive quality standards
BREAKING CHANGES:
- Renamed HandleGET -> MemberGET for member-level routes
- Renamed HandlePOST -> MemberPOST for member-level routes
- Renamed HandlePUT -> MemberPUT for member-level routes
- Renamed HandlePATCH -> MemberPATCH for member-level routes
- Renamed HandleDELETE -> MemberDELETE for member-level routes
New Features:
- Added collection-level route methods: GET, POST, PUT, PATCH, DELETE
- Clear distinction between collection (/pattern/action) and member (/pattern/{id}/action) routes
- Comprehensive documentation (README, CONTRIBUTING, QUICKSTART, DOCS)
- Development tooling (Makefile, check.sh script)
- AI coding assistant guidelines (.cursorrules)
- GitHub Actions CI/CD pipeline
- golangci-lint configuration
Code Quality:
- Optimized struct field alignment for better memory usage
- All code passes go vet, staticcheck, and fieldalignment
- All tests pass with race detector
- Go 1.25+ requirement enforced
Documentation:
- Complete README rewrite with examples
- CONTRIBUTING.md with development guidelines
- QUICKSTART.md for new users
- CHANGELOG.md with version history
- SUMMARY.md documenting all changes
- DOCS.md as documentation index
2025-11-15 14:05:11 +05:30
|
|
|
mu sync.RWMutex
|
2025-08-16 11:19:45 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
}
|