Refactor core configuration and UUID handling

- Changed UUIDLength type from byte to int in core/config/consts.go
- Introduced MetaDir constant in core/config/consts.go
- Added corestate package with initial state management and UUID handling
- Implemented GetNodeUUID and SetNodeUUID functions for UUID file management
- Created RunManager and RunFileManager for runtime directory management
- Updated GeneralServer to use new configuration structure
- Removed deprecated init package and replaced with main entry point
- Added color utility functions for logging
- Enhanced UUID generation functions in utils package
- Updated update logic to handle new configuration structure
- Added routines for cleaning temporary runtime directories
- Introduced response formatting for API responses
This commit is contained in:
alex
2025-07-09 01:21:34 +03:00
parent 8d01314ded
commit 9919f77c90
31 changed files with 1186 additions and 275 deletions

View File

@@ -8,13 +8,15 @@ import (
"path/filepath"
"strings"
"github.com/akyaiy/GoSally-mvp/core/config"
"github.com/akyaiy/GoSally-mvp/core/corestate"
"github.com/akyaiy/GoSally-mvp/core/utils"
"github.com/go-chi/chi/v5"
)
// The function processes the HTTP request and returns a list of available commands.
func (h *HandlerV1) HandleList(w http.ResponseWriter, r *http.Request) {
uuid16, err := utils.NewUUID()
uuid16, err := utils.NewUUID(int(config.GetInternalConsts().GetUUIDLength()))
if err != nil {
h.log.Error("Failed to generate UUID",
slog.String("error", err.Error()))
@@ -109,9 +111,14 @@ func (h *HandlerV1) HandleList(w http.ResponseWriter, r *http.Request) {
log.Debug("Command list prepared")
log.Info("Session completed")
uuid32, _ := corestate.GetNodeUUID(filepath.Join(config.GetInternalConsts().GetMetaDir(), "uuid"))
response := ResponseFormat{
ResponsibleAgentUUID: uuid32,
RequestedCommand: "list",
Response: commands,
}
w.Header().Set("Content-Type", "application/json")
if err := json.NewEncoder(w).Encode(commands); err != nil {
if err := json.NewEncoder(w).Encode(response); err != nil {
h.log.Error("Failed to write JSON error response",
slog.String("error", err.Error()))
}