BackGo/config/default.go

65 lines
2.9 KiB
Go

package config
import (
"fmt"
"os"
"time"
)
// SetDefaultConfig sets the default configuration by writing to environment variables
// and create a default configuration file.
func SetDefaultConfig() error {
// Define default values with explanations
defaults := map[string]string{
// Logging level: DEBUG, INFO, WARNING, ERROR
"LOG_LEVEL": "INFO",
// API server configuration
"API_SERVER_BIND_ADDRESS": "0.0.0.0", // IP address to bind the API server
"API_SERVER_PORT": "6678", // Port for the API server
// Transport server configuration for internal communication
"TRANSPORT_SERVER_BIND_ADDRESS": "0.0.0.0", // IP address for the transport server
"TRANSPORT_SERVER_PORT": "6679", // Port for the transport server
// S3 storage configuration
"S3_ENABLED": "false", // Enable S3 storage (true/false)
"S3_CONNECTION_ADDRESS": "", // S3 connection address in the format {IP}:{PORT}
"S3_AUTHORIZATION_INFO": "", // S3 authorization information (e.g., access key and secret key)
"S3_REGION": "us-east-1", // AWS region for S3
"S3_BUCKET_INFO": "", // S3 bucket name
// SMB storage configuration
"SMB_ENABLED": "false", // Enable SMB storage (true/false)
"SMB_CONNECTION_ADDRESS": "", // SMB connection address in the format {IP}:{PORT}
"SMB_AUTHORIZATION_INFO": "", // SMB authorization information (e.g., username and password)
// BackBlaze B2 storage configuration
"B2_ENABLED": "false", // Enable BackBlaze B2 storage (true/false)
"B2_CONNECTION_ADDRESS":"", // BackBlaze B2 connection address in the format {IP}:{PORT}
"B2_AUTHORIZATION_INFO":"", // BackBlaze B2 authorization information
"B2_BUCKET_INFO": "", // BackBlaze B2 bucket name
// Local storage configuration
"LOCAL_STORAGE_ENABLED": "true", // Enable local storage (true/false)
"LOCAL_STORAGE_DIRECTORY": fmt.Sprintf("/etc/PixelRidge/BackGo/local-data-storage/%s-%d", os.Getenv("HOSTNAME"), time.Now().Unix()), // Path for local storage directory
// Nodes configuration for cluster setup
"NODES": "", // Comma-separated list of node addresses in the cluster
}
// Write defaults to environment variables
for key, value := range defaults {
if err := os.Setenv(key, value); err != nil {
return fmt.Errorf("failed to set default config for %s: %v", key, err)
}
}
// write these defaults to a file for persistence
// write to a JSON or YAML file
return nil
}
// include a function here to write the configuration to a file