mirror of
https://github.com/lordmathis/llamactl.git
synced 2025-11-06 00:54:23 +00:00
Fix instance name retrieval
This commit is contained in:
@@ -10,6 +10,8 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/go-chi/chi/v5"
|
||||||
)
|
)
|
||||||
|
|
||||||
// errorResponse represents an error response returned by the API
|
// errorResponse represents an error response returned by the API
|
||||||
@@ -65,7 +67,7 @@ func NewHandler(im manager.InstanceManager, cfg config.AppConfig) *Handler {
|
|||||||
|
|
||||||
// getInstance retrieves an instance by name from the request query parameters
|
// getInstance retrieves an instance by name from the request query parameters
|
||||||
func (h *Handler) getInstance(r *http.Request) (*instance.Instance, error) {
|
func (h *Handler) getInstance(r *http.Request) (*instance.Instance, error) {
|
||||||
name := r.URL.Query().Get("name")
|
name := chi.URLParam(r, "name")
|
||||||
validatedName, err := validation.ValidateInstanceName(name)
|
validatedName, err := validation.ValidateInstanceName(name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("invalid instance name: %w", err)
|
return nil, fmt.Errorf("invalid instance name: %w", err)
|
||||||
|
|||||||
@@ -9,6 +9,8 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/go-chi/chi/v5"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ListInstances godoc
|
// ListInstances godoc
|
||||||
@@ -47,7 +49,7 @@ func (h *Handler) ListInstances() http.HandlerFunc {
|
|||||||
// @Router /instances/{name} [post]
|
// @Router /instances/{name} [post]
|
||||||
func (h *Handler) CreateInstance() http.HandlerFunc {
|
func (h *Handler) CreateInstance() http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
name := r.URL.Query().Get("name")
|
name := chi.URLParam(r, "name")
|
||||||
validatedName, err := validation.ValidateInstanceName(name)
|
validatedName, err := validation.ValidateInstanceName(name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
writeError(w, http.StatusBadRequest, "invalid_instance_name", err.Error())
|
writeError(w, http.StatusBadRequest, "invalid_instance_name", err.Error())
|
||||||
@@ -83,7 +85,7 @@ func (h *Handler) CreateInstance() http.HandlerFunc {
|
|||||||
// @Router /instances/{name} [get]
|
// @Router /instances/{name} [get]
|
||||||
func (h *Handler) GetInstance() http.HandlerFunc {
|
func (h *Handler) GetInstance() http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
name := r.URL.Query().Get("name")
|
name := chi.URLParam(r, "name")
|
||||||
validatedName, err := validation.ValidateInstanceName(name)
|
validatedName, err := validation.ValidateInstanceName(name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
writeError(w, http.StatusBadRequest, "invalid_instance_name", err.Error())
|
writeError(w, http.StatusBadRequest, "invalid_instance_name", err.Error())
|
||||||
@@ -115,7 +117,7 @@ func (h *Handler) GetInstance() http.HandlerFunc {
|
|||||||
// @Router /instances/{name} [put]
|
// @Router /instances/{name} [put]
|
||||||
func (h *Handler) UpdateInstance() http.HandlerFunc {
|
func (h *Handler) UpdateInstance() http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
name := r.URL.Query().Get("name")
|
name := chi.URLParam(r, "name")
|
||||||
validatedName, err := validation.ValidateInstanceName(name)
|
validatedName, err := validation.ValidateInstanceName(name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
writeError(w, http.StatusBadRequest, "invalid_instance_name", err.Error())
|
writeError(w, http.StatusBadRequest, "invalid_instance_name", err.Error())
|
||||||
@@ -151,7 +153,7 @@ func (h *Handler) UpdateInstance() http.HandlerFunc {
|
|||||||
// @Router /instances/{name}/start [post]
|
// @Router /instances/{name}/start [post]
|
||||||
func (h *Handler) StartInstance() http.HandlerFunc {
|
func (h *Handler) StartInstance() http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
name := r.URL.Query().Get("name")
|
name := chi.URLParam(r, "name")
|
||||||
validatedName, err := validation.ValidateInstanceName(name)
|
validatedName, err := validation.ValidateInstanceName(name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
writeError(w, http.StatusBadRequest, "invalid_instance_name", err.Error())
|
writeError(w, http.StatusBadRequest, "invalid_instance_name", err.Error())
|
||||||
@@ -187,7 +189,7 @@ func (h *Handler) StartInstance() http.HandlerFunc {
|
|||||||
// @Router /instances/{name}/stop [post]
|
// @Router /instances/{name}/stop [post]
|
||||||
func (h *Handler) StopInstance() http.HandlerFunc {
|
func (h *Handler) StopInstance() http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
name := r.URL.Query().Get("name")
|
name := chi.URLParam(r, "name")
|
||||||
validatedName, err := validation.ValidateInstanceName(name)
|
validatedName, err := validation.ValidateInstanceName(name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
writeError(w, http.StatusBadRequest, "invalid_instance_name", err.Error())
|
writeError(w, http.StatusBadRequest, "invalid_instance_name", err.Error())
|
||||||
@@ -217,7 +219,7 @@ func (h *Handler) StopInstance() http.HandlerFunc {
|
|||||||
// @Router /instances/{name}/restart [post]
|
// @Router /instances/{name}/restart [post]
|
||||||
func (h *Handler) RestartInstance() http.HandlerFunc {
|
func (h *Handler) RestartInstance() http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
name := r.URL.Query().Get("name")
|
name := chi.URLParam(r, "name")
|
||||||
validatedName, err := validation.ValidateInstanceName(name)
|
validatedName, err := validation.ValidateInstanceName(name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
writeError(w, http.StatusBadRequest, "invalid_instance_name", err.Error())
|
writeError(w, http.StatusBadRequest, "invalid_instance_name", err.Error())
|
||||||
@@ -246,7 +248,7 @@ func (h *Handler) RestartInstance() http.HandlerFunc {
|
|||||||
// @Router /instances/{name} [delete]
|
// @Router /instances/{name} [delete]
|
||||||
func (h *Handler) DeleteInstance() http.HandlerFunc {
|
func (h *Handler) DeleteInstance() http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
name := r.URL.Query().Get("name")
|
name := chi.URLParam(r, "name")
|
||||||
validatedName, err := validation.ValidateInstanceName(name)
|
validatedName, err := validation.ValidateInstanceName(name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
writeError(w, http.StatusBadRequest, "invalid_instance_name", err.Error())
|
writeError(w, http.StatusBadRequest, "invalid_instance_name", err.Error())
|
||||||
@@ -276,7 +278,7 @@ func (h *Handler) DeleteInstance() http.HandlerFunc {
|
|||||||
// @Router /instances/{name}/logs [get]
|
// @Router /instances/{name}/logs [get]
|
||||||
func (h *Handler) GetInstanceLogs() http.HandlerFunc {
|
func (h *Handler) GetInstanceLogs() http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
name := r.URL.Query().Get("name")
|
name := chi.URLParam(r, "name")
|
||||||
validatedName, err := validation.ValidateInstanceName(name)
|
validatedName, err := validation.ValidateInstanceName(name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
writeError(w, http.StatusBadRequest, "invalid_instance_name", err.Error())
|
writeError(w, http.StatusBadRequest, "invalid_instance_name", err.Error())
|
||||||
|
|||||||
Reference in New Issue
Block a user