added Dockerfile & added --port --domain --skip-config-check flags

This commit is contained in:
partisan 2024-11-21 12:30:16 +01:00
parent 3ca7d57680
commit 28f71271d7
5 changed files with 249 additions and 18 deletions

49
init.go
View file

@ -1,6 +1,8 @@
package main
import (
"flag"
"os"
"time"
)
@ -35,14 +37,43 @@ const configFilePath = "config.ini"
var config Config
func main() {
err := initConfig()
if err != nil {
printErr("Error during initialization:")
return
// Command-line flags
portFlag := flag.Int("port", 0, "Port number to run the application (overrides config)")
domainFlag := flag.String("domain", "", "Domain address for the application (overrides config)")
skipConfigFlag := flag.Bool("skip-config-check", false, "Skip interactive prompts and load config.ini")
// Parse command-line flags
flag.Parse()
if *skipConfigFlag {
// Skip interactive configuration
if _, err := os.Stat(configFilePath); err == nil {
// Load from config file if it exists
config = loadConfig()
} else {
// Use defaults if config file does not exist
config = defaultConfig
saveConfig(config) // Save the defaults to config.ini
printInfo("Configuration saved to %s", configFilePath)
}
} else {
// Initialize configuration interactively or from config file
err := initConfig()
if err != nil {
printErr("Error during initialization:")
return
}
}
// Override with command-line arguments if provided
if *portFlag != 0 {
config.Port = *portFlag
}
if *domainFlag != "" {
config.Domain = *domainFlag
}
loadNodeConfig()
// go checkMasterHeartbeat() // Not currently used
if config.AuthCode == "" {
config.AuthCode = generateStrongRandomString(64)
@ -57,14 +88,6 @@ func main() {
}
config.PeerID = hostID
// if len(config.Peers) > 0 {
// time.Sleep(2 * time.Second) // Give some time for connections to establish
// startElection()
// }
// Start automatic update checker, not used now
//go checkForUpdates()
InitializeLanguage("en") // Initialize language before generating OpenSearch
generateOpenSearchXML(config)