8460: Receive events and broadcast to clients.
[arvados.git] / services / ws / main.go
index ce56d0d5fddc32973da04de855f74102bf66212a..0f978231b9658068bd8351a582c4328d3383e1e0 100644 (file)
@@ -2,6 +2,7 @@ package main
 
 import (
        "flag"
+       "fmt"
        "log"
        "net/http"
        "time"
@@ -9,13 +10,30 @@ import (
        "git.curoverse.com/arvados.git/sdk/go/config"
 )
 
+var debugLogf = func(string, ...interface{}) {}
+
 func main() {
        configPath := flag.String("config", "/etc/arvados/ws/ws.yml", "`path` to config file")
+       dumpConfig := flag.Bool("dump-config", false, "show current configuration and exit")
        cfg := DefaultConfig()
+       flag.Parse()
+
        err := config.LoadFile(&cfg, *configPath)
        if err != nil {
                log.Fatal(err)
        }
+       if cfg.Debug {
+               debugLogf = log.Printf
+       }
+
+       if *dumpConfig {
+               txt, err := config.Dump(&cfg)
+               if err != nil {
+                       log.Fatal(err)
+               }
+               fmt.Print(string(txt))
+               return
+       }
 
        srv := &http.Server{
                Addr:           cfg.Listen,
@@ -23,10 +41,11 @@ func main() {
                WriteTimeout:   time.Minute,
                MaxHeaderBytes: 1 << 20,
                Handler: &router{
-                       EventSource: (&pgEventSource{
+                       Config: &cfg,
+                       eventSource: &pgEventSource{
                                PgConfig:  cfg.Postgres,
                                QueueSize: cfg.ServerEventQueue,
-                       }).EventSource(),
+                       },
                },
        }
        log.Fatal(srv.ListenAndServe())