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"
|
"net/http"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/go-chi/chi/v5"
|
|
||||||
"fuego/internal/auth"
|
|
||||||
"fuego/pkg/types"
|
"fuego/pkg/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -169,4 +167,3 @@ func (s *Server) handleListRunnersAdmin(w http.ResponseWriter, r *http.Request)
|
|||||||
|
|
||||||
s.respondJSON(w, http.StatusOK, runners)
|
s.respondJSON(w, http.StatusOK, runners)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,21 +10,22 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
"time"
|
"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"
|
||||||
"github.com/go-chi/chi/v5/middleware"
|
"github.com/go-chi/chi/v5/middleware"
|
||||||
"github.com/go-chi/cors"
|
"github.com/go-chi/cors"
|
||||||
"github.com/gorilla/websocket"
|
"github.com/gorilla/websocket"
|
||||||
"fuego/internal/auth"
|
|
||||||
"fuego/internal/database"
|
|
||||||
"fuego/internal/storage"
|
|
||||||
"fuego/pkg/types"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Server represents the API server
|
// Server represents the API server
|
||||||
type Server struct {
|
type Server struct {
|
||||||
db *database.DB
|
db *database.DB
|
||||||
auth *auth.Auth
|
auth *authpkg.Auth
|
||||||
secrets *auth.Secrets
|
secrets *authpkg.Secrets
|
||||||
storage *storage.Storage
|
storage *storage.Storage
|
||||||
router *chi.Mux
|
router *chi.Mux
|
||||||
|
|
||||||
@@ -37,8 +38,8 @@ type Server struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NewServer creates a new API server
|
// NewServer creates a new API server
|
||||||
func NewServer(db *database.DB, auth *auth.Auth, storage *storage.Storage) (*Server, error) {
|
func NewServer(db *database.DB, auth *authpkg.Auth, storage *storage.Storage) (*Server, error) {
|
||||||
secrets, err := auth.NewSecrets(db.DB)
|
secrets, err := authpkg.NewSecrets(db.DB)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to initialize secrets: %w", err)
|
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
|
// Helper to get user ID from context
|
||||||
func getUserID(r *http.Request) (int64, error) {
|
func getUserID(r *http.Request) (int64, error) {
|
||||||
userID, ok := auth.GetUserID(r.Context())
|
userID, ok := authpkg.GetUserID(r.Context())
|
||||||
if !ok {
|
if !ok {
|
||||||
return 0, fmt.Errorf("user ID not found in context")
|
return 0, fmt.Errorf("user ID not found in context")
|
||||||
}
|
}
|
||||||
@@ -510,4 +511,3 @@ func (s *Server) recoverTaskTimeouts() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -20,8 +20,9 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/gorilla/websocket"
|
|
||||||
"fuego/pkg/types"
|
"fuego/pkg/types"
|
||||||
|
|
||||||
|
"github.com/gorilla/websocket"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Client represents a runner client
|
// Client represents a runner client
|
||||||
@@ -35,7 +36,7 @@ type Client struct {
|
|||||||
runnerSecret string
|
runnerSecret string
|
||||||
managerSecret string
|
managerSecret string
|
||||||
wsConn *websocket.Conn
|
wsConn *websocket.Conn
|
||||||
wsConnMu sync.Mutex
|
wsConnMu sync.RWMutex
|
||||||
stopChan chan struct{}
|
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")
|
return fmt.Errorf("WebSocket not connected, cannot complete task")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user