80 lines
1.8 KiB
Go
80 lines
1.8 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
"github.com/konduktor/konduktor/internal/config"
|
|
"github.com/konduktor/konduktor/internal/server"
|
|
)
|
|
|
|
var (
|
|
Version = "0.1.0"
|
|
BuildTime = "unknown"
|
|
GitCommit = "unknown"
|
|
)
|
|
|
|
var (
|
|
cfgFile string
|
|
host string
|
|
port int
|
|
debug bool
|
|
)
|
|
|
|
func main() {
|
|
rootCmd := &cobra.Command{
|
|
Use: "konduktor",
|
|
Short: "Konduktor - HTTP web server",
|
|
Long: `Konduktor is a high-performance HTTP web server with extensible routing and process orchestration.`,
|
|
Version: fmt.Sprintf("%s (commit: %s, built: %s)", Version, GitCommit, BuildTime),
|
|
RunE: runServer,
|
|
}
|
|
|
|
rootCmd.Flags().StringVarP(&cfgFile, "config", "c", "config.yaml", "Path to configuration file")
|
|
rootCmd.Flags().StringVar(&host, "host", "", "Host to bind the server to")
|
|
rootCmd.Flags().IntVar(&port, "port", 0, "Port to bind the server to")
|
|
rootCmd.Flags().BoolVar(&debug, "debug", false, "Enable debug mode")
|
|
|
|
if err := rootCmd.Execute(); err != nil {
|
|
fmt.Fprintln(os.Stderr, err)
|
|
os.Exit(1)
|
|
}
|
|
}
|
|
|
|
func runServer(cmd *cobra.Command, args []string) error {
|
|
cfg, err := config.Load(cfgFile)
|
|
if err != nil {
|
|
if os.IsNotExist(err) {
|
|
fmt.Printf("Configuration file %s not found, using defaults\n", cfgFile)
|
|
cfg = config.Default()
|
|
} else {
|
|
return fmt.Errorf("configuration loading error: %w", err)
|
|
}
|
|
}
|
|
|
|
if host != "" {
|
|
cfg.Server.Host = host
|
|
}
|
|
if port != 0 {
|
|
cfg.Server.Port = port
|
|
}
|
|
if debug {
|
|
cfg.Logging.Level = "DEBUG"
|
|
}
|
|
|
|
srv, err := server.New(cfg)
|
|
if err != nil {
|
|
return fmt.Errorf("server creation error: %w", err)
|
|
}
|
|
|
|
fmt.Printf("Starting Konduktor server on %s:%d\n", cfg.Server.Host, cfg.Server.Port)
|
|
|
|
if err := srv.Run(); err != nil {
|
|
return fmt.Errorf("server startup error: %w", err)
|
|
}
|
|
|
|
return nil
|
|
}
|