Initial commit
This commit is contained in:
79
cmd/pekoe/main.go
Normal file
79
cmd/pekoe/main.go
Normal file
@@ -0,0 +1,79 @@
|
||||
// @tag entrypoint
|
||||
// @tag config
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/eleksir/pekoe/internal/config"
|
||||
"github.com/eleksir/pekoe/internal/logger"
|
||||
"github.com/eleksir/pekoe/internal/pubsub"
|
||||
"github.com/eleksir/pekoe/internal/server"
|
||||
)
|
||||
|
||||
var version = "unknown"
|
||||
|
||||
func main() {
|
||||
// Parse command-line flags
|
||||
configPath := flag.String("config", "", "Path to configuration file")
|
||||
showVersion := flag.Bool("version", false, "Show version information")
|
||||
flag.Parse()
|
||||
|
||||
if *showVersion {
|
||||
fmt.Printf("Pekoe Redis Pub/Sub Server v%s\n", version)
|
||||
fmt.Println("Built with Go, no external dependencies")
|
||||
return
|
||||
}
|
||||
|
||||
// Resolve config file path
|
||||
path, err := resolveConfigPath(*configPath)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
// Load configuration
|
||||
cfg, err := config.Load(path)
|
||||
if err != nil {
|
||||
logger.Fatal("Failed to load config from %s: %v", path, err)
|
||||
}
|
||||
|
||||
logger.Info("Configuration loaded from %s: %s", path, cfg.Addr())
|
||||
|
||||
// Create pubsub hub - the core of our pub/sub system
|
||||
hub := pubsub.NewHub()
|
||||
logger.Info("PubSub hub initialized")
|
||||
|
||||
// Create and start the server
|
||||
srv := server.New(cfg, hub)
|
||||
if err := srv.Run(); err != nil {
|
||||
logger.Fatal("Server error: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
// resolveConfigPath determines which config file to use.
|
||||
// If --config is given, that path is used directly.
|
||||
// Otherwise, platform-specific default paths are tried in order.
|
||||
func resolveConfigPath(explicit string) (string, error) {
|
||||
if explicit != "" {
|
||||
if _, err := os.Stat(explicit); err != nil {
|
||||
return "", fmt.Errorf("config file not found: %s", explicit)
|
||||
}
|
||||
return explicit, nil
|
||||
}
|
||||
|
||||
paths := config.DefaultConfigPaths()
|
||||
if len(paths) == 0 {
|
||||
return "", fmt.Errorf("no config file found, use --config to specify a config file")
|
||||
}
|
||||
|
||||
for _, p := range paths {
|
||||
if _, err := os.Stat(p); err == nil {
|
||||
return p, nil
|
||||
}
|
||||
}
|
||||
|
||||
return "", fmt.Errorf("no config file found, tried: %v", paths)
|
||||
}
|
||||
Reference in New Issue
Block a user