Refactor imports and clean up whitespace in API and runner client files. Update auth package references to use the new package structure. Improve mutex usage in the runner client for better concurrency handling.
This commit is contained in:
@@ -7,8 +7,6 @@ import (
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"github.com/go-chi/chi/v5"
|
||||
"fuego/internal/auth"
|
||||
"fuego/pkg/types"
|
||||
)
|
||||
|
||||
@@ -169,4 +167,3 @@ func (s *Server) handleListRunnersAdmin(w http.ResponseWriter, r *http.Request)
|
||||
|
||||
s.respondJSON(w, http.StatusOK, runners)
|
||||
}
|
||||
|
||||
|
||||
@@ -10,21 +10,22 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
authpkg "fuego/internal/auth"
|
||||
"fuego/internal/database"
|
||||
"fuego/internal/storage"
|
||||
"fuego/pkg/types"
|
||||
|
||||
"github.com/go-chi/chi/v5"
|
||||
"github.com/go-chi/chi/v5/middleware"
|
||||
"github.com/go-chi/cors"
|
||||
"github.com/gorilla/websocket"
|
||||
"fuego/internal/auth"
|
||||
"fuego/internal/database"
|
||||
"fuego/internal/storage"
|
||||
"fuego/pkg/types"
|
||||
)
|
||||
|
||||
// Server represents the API server
|
||||
type Server struct {
|
||||
db *database.DB
|
||||
auth *auth.Auth
|
||||
secrets *auth.Secrets
|
||||
auth *authpkg.Auth
|
||||
secrets *authpkg.Secrets
|
||||
storage *storage.Storage
|
||||
router *chi.Mux
|
||||
|
||||
@@ -37,8 +38,8 @@ type Server struct {
|
||||
}
|
||||
|
||||
// NewServer creates a new API server
|
||||
func NewServer(db *database.DB, auth *auth.Auth, storage *storage.Storage) (*Server, error) {
|
||||
secrets, err := auth.NewSecrets(db.DB)
|
||||
func NewServer(db *database.DB, auth *authpkg.Auth, storage *storage.Storage) (*Server, error) {
|
||||
secrets, err := authpkg.NewSecrets(db.DB)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to initialize secrets: %w", err)
|
||||
}
|
||||
@@ -290,7 +291,7 @@ func (s *Server) handleGetMe(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
// Helper to get user ID from context
|
||||
func getUserID(r *http.Request) (int64, error) {
|
||||
userID, ok := auth.GetUserID(r.Context())
|
||||
userID, ok := authpkg.GetUserID(r.Context())
|
||||
if !ok {
|
||||
return 0, fmt.Errorf("user ID not found in context")
|
||||
}
|
||||
@@ -510,4 +511,3 @@ func (s *Server) recoverTaskTimeouts() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -20,8 +20,9 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/gorilla/websocket"
|
||||
"fuego/pkg/types"
|
||||
|
||||
"github.com/gorilla/websocket"
|
||||
)
|
||||
|
||||
// Client represents a runner client
|
||||
@@ -35,7 +36,7 @@ type Client struct {
|
||||
runnerSecret string
|
||||
managerSecret string
|
||||
wsConn *websocket.Conn
|
||||
wsConnMu sync.Mutex
|
||||
wsConnMu sync.RWMutex
|
||||
stopChan chan struct{}
|
||||
}
|
||||
|
||||
@@ -813,4 +814,3 @@ func (c *Client) sendTaskComplete(taskID int64, outputPath string, success bool,
|
||||
}
|
||||
return fmt.Errorf("WebSocket not connected, cannot complete task")
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user