Search/init.go

75 lines
1.5 KiB
Go
Raw Normal View History

2024-06-12 14:26:50 +02:00
package main
import (
2024-08-08 13:35:50 +02:00
"time"
2024-06-12 14:26:50 +02:00
)
type Config struct {
2024-10-13 00:04:46 +02:00
Port int
AuthCode string
PeerID string
Peers []string
Domain string
NodesEnabled bool
CrawlerEnabled bool
WebsiteEnabled bool
LogLevel int
HardCacheDuration time.Duration
2024-10-14 22:15:38 +02:00
HardCacheEnabled bool
2024-06-12 14:26:50 +02:00
}
var defaultConfig = Config{
2024-10-13 00:04:46 +02:00
Port: 5000,
Domain: "localhost",
Peers: []string{},
AuthCode: generateStrongRandomString(64),
NodesEnabled: true,
CrawlerEnabled: true,
WebsiteEnabled: true,
LogLevel: 1,
HardCacheDuration: 0,
2024-06-12 14:26:50 +02:00
}
2024-08-08 15:03:33 +02:00
const configFilePath = "config.ini"
2024-06-12 14:26:50 +02:00
2024-07-05 03:08:35 +02:00
var config Config
2024-06-12 14:26:50 +02:00
func main() {
err := initConfig()
if err != nil {
2024-08-10 13:27:23 +02:00
printErr("Error during initialization:")
2024-06-12 14:26:50 +02:00
return
}
2024-06-30 23:20:52 +02:00
loadNodeConfig()
// go checkMasterHeartbeat() // Not currently used
2024-07-05 03:08:35 +02:00
if config.AuthCode == "" {
config.AuthCode = generateStrongRandomString(64)
2024-08-10 13:27:23 +02:00
printInfo("Generated connection code: %s\n", config.AuthCode)
2024-07-05 03:08:35 +02:00
saveConfig(config)
}
// Generate Host ID
hostID, nodeErr := generateHostID()
2024-08-08 13:35:50 +02:00
if nodeErr != nil {
2024-08-10 13:27:23 +02:00
printErr("Failed to generate host ID: %v", nodeErr)
2024-08-08 13:35:50 +02:00
}
config.PeerID = hostID
2024-08-08 13:35:50 +02:00
// if len(config.Peers) > 0 {
// time.Sleep(2 * time.Second) // Give some time for connections to establish
// startElection()
// }
2024-06-30 23:20:52 +02:00
// Start automatic update checker, not used now
//go checkForUpdates()
2024-10-25 13:54:29 +02:00
InitializeLanguage("en") // Initialize language before generating OpenSearch
generateOpenSearchXML(config)
2024-08-08 13:35:50 +02:00
go startNodeClient()
2024-06-12 14:26:50 +02:00
runServer()
}