BackGo/config/default.go
2024-03-28 18:48:18 -06:00

57 lines
1.5 KiB
Go

package config
import (
"fmt"
"os"
"time"
yaml "gopkg.in/yaml.v3"
)
func SetDefaultConfig() error {
cfg := Config{
LogLevel: LogLevelInfo,
MySQLUser: "mysql",
MySQLPassword: "pass",
MySQLHost: "localhost",
MySQLPort: "3306",
MySQLDBName: "backgo",
APIServerBindAddress: "0.0.0.0",
APIServerPort: "6678",
TransportServerBindAddress: "0.0.0.0",
TransportServerPort: "6679",
S3Enabled: false,
S3ConnectionAddress: "",
S3AuthorizationInfo: "",
S3Region: "us-east-1",
S3BucketInfo: "",
SMBEnabled: false,
SMBConnectionAddress: "",
SMBAuthorizationInfo: "",
B2Enabled: false,
B2ConnectionAddress: "",
B2AuthorizationInfo: "",
B2BucketInfo: "",
LocalStorageEnabled: true,
LocalStorageDirectory: fmt.Sprintf("/etc/PixelRidge/BackGo/local-data-storage/%s-%d", os.Getenv("HOSTNAME"), time.Now().Unix()),
Nodes: []string{},
}
return WriteConfigToFile(&cfg)
}
func WriteConfigToFile(cfg *Config) error {
file, err := os.OpenFile(configFilePath, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0644)
if err != nil {
return fmt.Errorf("failed to open config file for writing: %v", err)
}
defer file.Close()
encoder := yaml.NewEncoder(file)
encoder.SetIndent(2)
if err := encoder.Encode(cfg); err != nil {
return fmt.Errorf("failed to write config to file: %v", err)
}
return nil
}