artifacts.go
Overview
The artifacts.go file defines the ArtifactsAPIRouter, responsible for configuring and exposing REST API routes related to artifact management within the system. Specifically, it maps HTTP endpoints to the corresponding handlers provided by the ArtifactsAPIController. This router manages artifact-related operations scoped under application, user, and session hierarchies, enabling clients to list, retrieve (including specific versions), and delete artifacts associated with user sessions.
This file is part of the Router Setup subtopic and contributes to the overall REST API and Web Launchers functionality by routing HTTP requests to artifact-specific controller handlers.
Entities and Their Roles
ArtifactsAPIRouter
Description:
A router struct that encapsulates theArtifactsAPIControllerinstance and defines the HTTP routes relevant to artifact operations.Fields:
artifactsController *controllers.ArtifactsAPIController
Holds a reference to the controller implementing the business logic for artifact management.
Constructor:
NewArtifactsAPIRouter(controller *controllers.ArtifactsAPIController) *ArtifactsAPIRouter
Creates and returns a new instance ofArtifactsAPIRouterinitialized with the given controller.
Methods:
Routes() Routes
Returns a list ofRouteobjects defining HTTP methods, URL patterns, and handler functions for artifact-related API endpoints.
Detailed Explanation of Methods and Routes
NewArtifactsAPIRouter
func NewArtifactsAPIRouter(controller *controllers.ArtifactsAPIController) *ArtifactsAPIRouter {
return &ArtifactsAPIRouter{artifactsController: controller}
}
Parameters:
controller: Pointer to anArtifactsAPIControllerthat contains the logic for handling artifact API requests.
Returns:
A pointer to a newly instantiated
ArtifactsAPIRouter.
Usage Example:
controller := controllers.NewArtifactsAPIController(...)
router := NewArtifactsAPIRouter(controller)
This constructor method is typically called during the initialization of the REST API server to set up routing for artifact endpoints.
Routes
func (r *ArtifactsAPIRouter) Routes() Routes {
return Routes{
Route{
Name: "ListArtifacts",
Methods: []string{http.MethodGet},
Pattern: "/apps/{app_name}/users/{user_id}/sessions/{session_id}/artifacts",
HandlerFunc: r.artifactsController.ListArtifactsHandler,
},
Route{
Name: "LoadArtifact",
Methods: []string{http.MethodGet},
Pattern: "/apps/{app_name}/users/{user_id}/sessions/{session_id}/artifacts/{artifact_name}",
HandlerFunc: r.artifactsController.LoadArtifactHandler,
},
Route{
Name: "LoadArtifact",
Methods: []string{http.MethodGet},
Pattern: "/apps/{app_name}/users/{user_id}/sessions/{session_id}/artifacts/{artifact_name}/versions/{version}",
HandlerFunc: r.artifactsController.LoadArtifactVersionHandler,
},
Route{
Name: "DeleteArtifact",
Methods: []string{http.MethodDelete, http.MethodOptions},
Pattern: "/apps/{app_name}/users/{user_id}/sessions/{session_id}/artifacts/{artifact_name}",
HandlerFunc: r.artifactsController.DeleteArtifactHandler,
},
}
}
Returns:
A slice of
Routestructs, each defining:Name: Unique identifier for the route.Methods: Allowed HTTP methods for this route.Pattern: URL path pattern with path parameters.HandlerFunc: Function that processes the HTTP request.
Defined Routes:
ListArtifacts
HTTP Method: GET
URL Pattern:
/apps/{app_name}/users/{user_id}/sessions/{session_id}/artifactsHandler:
ListArtifactsHandlerDescription: Lists all artifacts associated with the specified application, user, and session.
LoadArtifact
HTTP Method: GET
URL Pattern:
/apps/{app_name}/users/{user_id}/sessions/{session_id}/artifacts/{artifact_name}Handler:
LoadArtifactHandlerDescription: Loads the latest version of a specified artifact by name.
LoadArtifact (Versioned)
HTTP Method: GET
URL Pattern:
/apps/{app_name}/users/{user_id}/sessions/{session_id}/artifacts/{artifact_name}/versions/{version}Handler:
LoadArtifactVersionHandlerDescription: Loads a specific version of an artifact.
DeleteArtifact
HTTP Methods: DELETE, OPTIONS
URL Pattern:
/apps/{app_name}/users/{user_id}/sessions/{session_id}/artifacts/{artifact_name}Handler:
DeleteArtifactHandlerDescription: Deletes the specified artifact from the session.
Usage:
This method is invoked by the HTTP router setup code to register the artifact-related endpoints with the HTTP server. Each route pattern includes path variables to scope artifact operations to a particular app, user, and session context.
Important Implementation Details
The router uses URL path parameters (
{app_name},{user_id},{session_id},{artifact_name},{version}) to uniquely identify the artifact context.HTTP methods are explicitly declared per route to enforce RESTful conventions (
GETfor retrieval,DELETEfor deletion).The handlers are methods of
ArtifactsAPIController, which encapsulate the business logic and interaction with the artifact storage backend (see Artifact Management for service details).The presence of an
OPTIONSmethod alongsideDELETEsupports CORS preflight requests for cross-origin deletion calls.This router is designed to be registered as a subrouter under a common API prefix (e.g.,
/api/) and combined with other routers likeSessionsAPIRouterorRuntimeAPIRouteras part of the overall Router Setup.
Interaction with Other Components
ArtifactsAPIController:
The controller implements the HTTP handlers invoked by this router. It interfaces with artifact services responsible for persistence, versioning, and retrieval.Session Management ([80559]):
Artifacts are scoped under sessions, so session validation and lifecycle management occur upstream or alongside these routes.REST API and Web Launchers ([80564]):
These routes are part of the full REST API server infrastructure, exposed to clients for managing artifacts via HTTP.Router Setup ([80592]):
ArtifactsAPIRouteris integrated into the main routing tree, ensuring consistent request dispatching across API domains.
Visual Diagram: ArtifactsAPIRouter Structure and Routes
classDiagram
class ArtifactsAPIRouter {
-artifactsController: ArtifactsAPIController
+NewArtifactsAPIRouter()
+Routes()
}
class Route {
+Name
+Methods
+Pattern
+HandlerFunc
}
ArtifactsAPIRouter --> "1" ArtifactsAPIController
ArtifactsAPIRouter "1" o-- "4" Route : defines
Route : "ListArtifacts\nGET /apps/{app}/users/{user}/sessions/{session}/artifacts"
Route : "LoadArtifact\nGET /.../artifacts/{artifact_name}"
Route : "LoadArtifactVersion\nGET /.../artifacts/{artifact_name}/versions/{version}"
Route : "DeleteArtifact\nDELETE /.../artifacts/{artifact_name}"
This class diagram represents ArtifactsAPIRouter holding a reference to its controller and defining four routes corresponding to artifact operations. Each route specifies an HTTP method, URL pattern, and handler function.
References
REST API and Web Launchers— for the overall API server framework and controller responsibilities.Router Setup— for the modular router architecture and integration into the HTTP server.Artifact Management— for artifact storage, versioning, and service interfaces.Sessions Management— to understand session scoping of artifacts.