-
Notifications
You must be signed in to change notification settings - Fork 4
Extract magic numbers to named constants #21
Description
Summary
Magic numbers are scattered throughout the codebase. These should be extracted to named constants for clarity and maintainability.
Current State
```go
// internal/api/router.go:42
r.Use(chimiddleware.Timeout(60 * time.Second))
// cmd/server/main.go:114-116
srv := &http.Server{
ReadTimeout: 30 * time.Second,
WriteTimeout: 30 * time.Second,
IdleTimeout: 120 * time.Second,
}
// cmd/server/main.go:146
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
// internal/tools/long_operation_sdk.go:52-57
if input.Seconds < 1 {
input.Seconds = 1
}
if input.Seconds > 60 {
input.Seconds = 60
}
// test/integration_test.go:126
if pag["maxPageSize"] != float64(100) {
```
Expected Outcome
Create constants file and use throughout:
```go
// internal/constants/constants.go
package constants
import "time"
const (
// HTTP Server Timeouts
DefaultRequestTimeout = 60 * time.Second
DefaultReadTimeout = 30 * time.Second
DefaultWriteTimeout = 30 * time.Second
DefaultIdleTimeout = 120 * time.Second
DefaultShutdownTimeout = 30 * time.Second
// Pagination
DefaultPageSize = 10
MaxPageSize = 100
// Long Operation Tool
MinOperationSeconds = 1
MaxOperationSeconds = 60
// Rate Limiting (for future use)
DefaultRateLimit = 100
DefaultBurstSize = 20
)
```
Then use:
```go
import "github.com/NP-compete/gomcp/internal/constants"
r.Use(chimiddleware.Timeout(constants.DefaultRequestTimeout))
```
Files to Update
- `internal/api/router.go`
- `cmd/server/main.go`
- `internal/tools/long_operation_sdk.go`
- `internal/pagination/pagination.go`
- `test/integration_test.go`
Acceptance Criteria
- Constants file created
- All magic numbers replaced with named constants
- Constants have descriptive names
- Constants have comments explaining their purpose
- All tests pass