Add new API endpoints and clean up handler interfaces: - groups/handlers.go: New lab group management API * CRUD operations for lab groups * Member management with role assignment (admin/member/viewer) * Group listing and membership queries - tokens/handlers.go: Token generation and validation endpoints * Create access tokens for public task sharing * Validate tokens for secure access * Token revocation and cleanup - routes.go: Refactor handler registration * Integrate groups handler into WebSocket routes * Remove nil parameters from all handler constructors * Cleaner dependency injection pattern - Handler interface cleanup across all modules: * jobs/handlers.go: Remove unused nil privacyEnforcer parameter * jupyter/handlers.go: Streamline initialization * scheduler/handlers.go: Consistent constructor signature * ws/handler.go: Add groups handler to dependencies
49 lines
1.8 KiB
Go
49 lines
1.8 KiB
Go
// Package helpers provides shared utilities for WebSocket handlers.
|
|
package helpers
|
|
|
|
import (
|
|
"context"
|
|
"slices"
|
|
"time"
|
|
)
|
|
|
|
// DBContext provides a standard database operation context.
|
|
// It creates a context with the specified timeout and returns the context and cancel function.
|
|
// #nosec G118 -- CancelFunc is returned to caller for proper lifecycle management
|
|
func DBContext(timeout time.Duration) (context.Context, context.CancelFunc) {
|
|
return context.WithTimeout(context.Background(), timeout)
|
|
}
|
|
|
|
// DBContextShort returns a short-lived context for quick DB operations (3 seconds).
|
|
// #nosec G118 -- CancelFunc is returned to caller for proper lifecycle management
|
|
func DBContextShort() (context.Context, context.CancelFunc) {
|
|
return context.WithTimeout(context.Background(), 3*time.Second)
|
|
}
|
|
|
|
// DBContextMedium returns a medium-lived context for standard DB operations (5 seconds).
|
|
// #nosec G118 -- CancelFunc is returned to caller for proper lifecycle management
|
|
func DBContextMedium() (context.Context, context.CancelFunc) {
|
|
return context.WithTimeout(context.Background(), 5*time.Second)
|
|
}
|
|
|
|
// DBContextLong returns a long-lived context for complex DB operations (10 seconds).
|
|
// #nosec G118 -- CancelFunc is returned to caller for proper lifecycle management
|
|
func DBContextLong() (context.Context, context.CancelFunc) {
|
|
return context.WithTimeout(context.Background(), 10*time.Second)
|
|
}
|
|
|
|
// StringSliceContains checks if a string slice contains a specific string.
|
|
func StringSliceContains(slice []string, item string) bool {
|
|
return slices.Contains(slice, item)
|
|
}
|
|
|
|
// StringSliceFilter filters a string slice based on a predicate.
|
|
func StringSliceFilter(slice []string, predicate func(string) bool) []string {
|
|
result := make([]string, 0)
|
|
for _, s := range slice {
|
|
if predicate(s) {
|
|
result = append(result, s)
|
|
}
|
|
}
|
|
return result
|
|
}
|