Files
GoSally/core/utils/uuid.go
alex 9919f77c90 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
2025-07-09 01:21:34 +03:00

42 lines
871 B
Go

package utils
import (
"crypto/rand"
"encoding/hex"
"errors"
"github.com/akyaiy/GoSally-mvp/core/config"
)
func NewUUIDRaw(length int) ([]byte, error) {
bytes := make([]byte, int(length))
_, err := rand.Read(bytes)
if err != nil {
return bytes, errors.New("failed to generate UUID: " + err.Error())
}
return bytes, nil
}
func NewUUID(length int) (string, error) {
data, err := NewUUIDRaw(length)
if err != nil {
return "", err
}
return hex.EncodeToString(data), nil
}
func NewUUID32() (string, error) {
return NewUUID(config.GetInternalConsts().GetUUIDLength())
}
func NewUUID32Raw() ([]byte, error) {
data, err := NewUUIDRaw(config.GetInternalConsts().GetUUIDLength())
if err != nil {
return data, err
}
if len(data) != config.GetInternalConsts().GetUUIDLength() {
return data, errors.New("unexpected UUID length")
}
return data, nil
}