@@ -27,8 +27,8 @@ type WorkloadRoutes struct {
27
27
// @title ToolHive API
28
28
// @version 1.0
29
29
// @description This is the ToolHive API workload.
30
- // @workloads [ { "url": "http://localhost:8080/api/v1 " } ]
31
- // @basePath /api/v1
30
+ // @workloads [ { "url": "http://localhost:8080/api/v1beta " } ]
31
+ // @basePath /api/v1beta
32
32
33
33
// WorkloadRouter creates a new WorkloadRoutes instance.
34
34
func WorkloadRouter (
@@ -51,10 +51,9 @@ func WorkloadRouter(
51
51
r .Get ("/{name}" , routes .getWorkload )
52
52
r .Post ("/{name}/stop" , routes .stopWorkload )
53
53
r .Post ("/{name}/restart" , routes .restartWorkload )
54
+ r .Get ("/{name}/logs" , routes .getLogsForWorkload )
54
55
r .Delete ("/{name}" , routes .deleteWorkload )
55
56
56
- // Mount the logs sub-router
57
- r .Mount ("/{name}" , LogsRouter (manager ))
58
57
return r
59
58
}
60
59
@@ -414,6 +413,39 @@ func (s *WorkloadRoutes) deleteWorkloadsBulk(w http.ResponseWriter, r *http.Requ
414
413
w .WriteHeader (http .StatusAccepted )
415
414
}
416
415
416
+ // getLogsForWorkload
417
+ //
418
+ // @Summary Get logs for a specific workload
419
+ // @Description Retrieve at most 100 lines of logs for a specific workload by name.
420
+ // @Tags logs
421
+ // @Produce text/plain
422
+ // @Param name path string true "Workload name"
423
+ // @Success 200 {string} string "Logs for the specified workload"
424
+ // @Failure 404 {string} string "Not Found"
425
+ // @Router /api/v1beta/workloads/{name}/logs [get]
426
+ func (s * WorkloadRoutes ) getLogsForWorkload (w http.ResponseWriter , r * http.Request ) {
427
+ ctx := r .Context ()
428
+ name := chi .URLParam (r , "name" )
429
+
430
+ logs , err := s .manager .GetLogs (ctx , name , false )
431
+ if err != nil {
432
+ if errors .Is (err , workloads .ErrContainerNotFound ) {
433
+ http .Error (w , "Workload not found" , http .StatusNotFound )
434
+ return
435
+ }
436
+ logger .Errorf ("Failed to get logs: %v" , err )
437
+ http .Error (w , "Failed to get logs" , http .StatusInternalServerError )
438
+ return
439
+ }
440
+ w .Header ().Set ("Content-Type" , "text/plain" )
441
+ _ , err = w .Write ([]byte (logs ))
442
+ if err != nil {
443
+ logger .Errorf ("Failed to write logs response: %v" , err )
444
+ http .Error (w , "Failed to write logs response" , http .StatusInternalServerError )
445
+ return
446
+ }
447
+ }
448
+
417
449
// Response type definitions.
418
450
419
451
// workloadListResponse represents the response for listing workloads
0 commit comments