mirror of
https://github.com/lordmathis/llamactl.git
synced 2025-11-05 16:44:22 +00:00
Refactor NodeConfig handling to use a map
This commit is contained in:
@@ -3,7 +3,6 @@ package server
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"llamactl/pkg/config"
|
||||
"llamactl/pkg/instance"
|
||||
"llamactl/pkg/manager"
|
||||
"net/http"
|
||||
@@ -414,15 +413,8 @@ func (h *Handler) RemoteInstanceProxy(w http.ResponseWriter, r *http.Request, na
|
||||
|
||||
if !exists {
|
||||
// Find node configuration
|
||||
var nodeConfig *config.NodeConfig
|
||||
for i := range h.cfg.Nodes {
|
||||
if h.cfg.Nodes[i].Name == nodeName {
|
||||
nodeConfig = &h.cfg.Nodes[i]
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if nodeConfig == nil {
|
||||
nodeConfig, exists := h.cfg.Nodes[nodeName]
|
||||
if !exists {
|
||||
http.Error(w, fmt.Sprintf("Node %s not found", nodeName), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@ package server
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"llamactl/pkg/config"
|
||||
"net/http"
|
||||
|
||||
"github.com/go-chi/chi/v5"
|
||||
@@ -10,26 +9,24 @@ import (
|
||||
|
||||
// NodeResponse represents a sanitized node configuration for API responses
|
||||
type NodeResponse struct {
|
||||
Name string `json:"name"`
|
||||
Address string `json:"address"`
|
||||
}
|
||||
|
||||
// ListNodes godoc
|
||||
// @Summary List all configured nodes
|
||||
// @Description Returns a list of all nodes configured in the server
|
||||
// @Description Returns a map of all nodes configured in the server (node name -> node config)
|
||||
// @Tags nodes
|
||||
// @Security ApiKeyAuth
|
||||
// @Produces json
|
||||
// @Success 200 {array} NodeResponse "List of nodes"
|
||||
// @Success 200 {object} map[string]NodeResponse "Map of nodes"
|
||||
// @Failure 500 {string} string "Internal Server Error"
|
||||
// @Router /nodes [get]
|
||||
func (h *Handler) ListNodes() http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
// Convert to sanitized response format
|
||||
nodeResponses := make([]NodeResponse, len(h.cfg.Nodes))
|
||||
for i, node := range h.cfg.Nodes {
|
||||
nodeResponses[i] = NodeResponse{
|
||||
Name: node.Name,
|
||||
// Convert to sanitized response format (map of name -> NodeResponse)
|
||||
nodeResponses := make(map[string]NodeResponse, len(h.cfg.Nodes))
|
||||
for name, node := range h.cfg.Nodes {
|
||||
nodeResponses[name] = NodeResponse{
|
||||
Address: node.Address,
|
||||
}
|
||||
}
|
||||
@@ -62,22 +59,14 @@ func (h *Handler) GetNode() http.HandlerFunc {
|
||||
return
|
||||
}
|
||||
|
||||
var nodeConfig *config.NodeConfig
|
||||
for i := range h.cfg.Nodes {
|
||||
if h.cfg.Nodes[i].Name == name {
|
||||
nodeConfig = &h.cfg.Nodes[i]
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if nodeConfig == nil {
|
||||
nodeConfig, exists := h.cfg.Nodes[name]
|
||||
if !exists {
|
||||
http.Error(w, "Node not found", http.StatusNotFound)
|
||||
return
|
||||
}
|
||||
|
||||
// Convert to sanitized response format
|
||||
nodeResponse := NodeResponse{
|
||||
Name: nodeConfig.Name,
|
||||
Address: nodeConfig.Address,
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,6 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"llamactl/pkg/config"
|
||||
"llamactl/pkg/instance"
|
||||
"net/http"
|
||||
"net/http/httputil"
|
||||
@@ -170,15 +169,8 @@ func (h *Handler) RemoteOpenAIProxy(w http.ResponseWriter, r *http.Request, mode
|
||||
|
||||
if !exists {
|
||||
// Find node configuration
|
||||
var nodeConfig *config.NodeConfig
|
||||
for i := range h.cfg.Nodes {
|
||||
if h.cfg.Nodes[i].Name == nodeName {
|
||||
nodeConfig = &h.cfg.Nodes[i]
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if nodeConfig == nil {
|
||||
nodeConfig, exists := h.cfg.Nodes[nodeName]
|
||||
if !exists {
|
||||
http.Error(w, fmt.Sprintf("Node %s not found", nodeName), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user