Add getInstance method to handlers

This commit is contained in:
2025-10-26 09:54:24 +01:00
parent 94dce4c9bb
commit 9259763054
3 changed files with 30 additions and 46 deletions

View File

@@ -6,6 +6,7 @@ import (
"llamactl/pkg/config"
"llamactl/pkg/instance"
"llamactl/pkg/manager"
"llamactl/pkg/validation"
"log"
"net/http"
"time"
@@ -56,6 +57,21 @@ func NewHandler(im manager.InstanceManager, cfg config.AppConfig) *Handler {
}
}
func (h *Handler) getInstance(r *http.Request) (*instance.Instance, error) {
name := r.URL.Query().Get("name")
validatedName, err := validation.ValidateInstanceName(name)
if err != nil {
return nil, fmt.Errorf("invalid instance name: %w", err)
}
inst, err := h.InstanceManager.GetInstance(validatedName)
if err != nil {
return nil, fmt.Errorf("failed to get instance by name: %w", err)
}
return inst, nil
}
func (h *Handler) ensureInstanceRunning(inst *instance.Instance) error {
options := inst.GetOptions()
allowOnDemand := options != nil && options.OnDemandStart != nil && *options.OnDemandStart