mirror of
https://github.com/DeBrosOfficial/network.git
synced 2026-01-30 16:13:04 +00:00
- Updated the API gateway documentation to reflect changes in architecture and functionality, emphasizing its role as a multi-functional entry point for decentralized services. - Refactored CLI commands to utilize utility functions for better code organization and maintainability. - Introduced new utility functions for handling peer normalization, service management, and port validation, enhancing the overall CLI experience. - Added a new production installation script to streamline the setup process for users, including detailed dry-run summaries for better visibility. - Enhanced validation mechanisms for configuration files and swarm keys, ensuring robust error handling and user feedback during setup.
59 lines
1.3 KiB
Go
59 lines
1.3 KiB
Go
package rqlite
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
"time"
|
|
)
|
|
|
|
func (r *RQLiteManager) rqliteDataDirPath() (string, error) {
|
|
dataDir := os.ExpandEnv(r.dataDir)
|
|
if strings.HasPrefix(dataDir, "~") {
|
|
home, _ := os.UserHomeDir()
|
|
dataDir = filepath.Join(home, dataDir[1:])
|
|
}
|
|
return filepath.Join(dataDir, "rqlite"), nil
|
|
}
|
|
|
|
func (r *RQLiteManager) resolveMigrationsDir() (string, error) {
|
|
productionPath := "/home/debros/src/migrations"
|
|
if _, err := os.Stat(productionPath); err == nil {
|
|
return productionPath, nil
|
|
}
|
|
return "migrations", nil
|
|
}
|
|
|
|
func (r *RQLiteManager) prepareDataDir() (string, error) {
|
|
rqliteDataDir, err := r.rqliteDataDirPath()
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
if err := os.MkdirAll(rqliteDataDir, 0755); err != nil {
|
|
return "", err
|
|
}
|
|
return rqliteDataDir, nil
|
|
}
|
|
|
|
func (r *RQLiteManager) hasExistingState(rqliteDataDir string) bool {
|
|
entries, err := os.ReadDir(rqliteDataDir)
|
|
if err != nil {
|
|
return false
|
|
}
|
|
for _, e := range entries {
|
|
if e.Name() != "." && e.Name() != ".." {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|
|
|
|
func (r *RQLiteManager) exponentialBackoff(attempt int, baseDelay time.Duration, maxDelay time.Duration) time.Duration {
|
|
delay := baseDelay * time.Duration(1<<uint(attempt))
|
|
if delay > maxDelay {
|
|
delay = maxDelay
|
|
}
|
|
return delay
|
|
}
|
|
|