8460: Hide *websocket.Conn behind interface.
[arvados.git] / services / ws / main.go
1 package main
2
3 import (
4         "flag"
5         "fmt"
6         "log"
7         "net/http"
8         "time"
9
10         "git.curoverse.com/arvados.git/sdk/go/config"
11 )
12
13 var debugLogf = func(string, ...interface{}) {}
14
15 func main() {
16         configPath := flag.String("config", "/etc/arvados/ws/ws.yml", "`path` to config file")
17         dumpConfig := flag.Bool("dump-config", false, "show current configuration and exit")
18         cfg := DefaultConfig()
19         flag.Parse()
20
21         err := config.LoadFile(&cfg, *configPath)
22         if err != nil {
23                 log.Fatal(err)
24         }
25         if cfg.Debug {
26                 debugLogf = log.Printf
27         }
28
29         if *dumpConfig {
30                 txt, err := config.Dump(&cfg)
31                 if err != nil {
32                         log.Fatal(err)
33                 }
34                 fmt.Print(string(txt))
35                 return
36         }
37
38         srv := &http.Server{
39                 Addr:           cfg.Listen,
40                 ReadTimeout:    time.Minute,
41                 WriteTimeout:   time.Minute,
42                 MaxHeaderBytes: 1 << 20,
43                 Handler: &router{
44                         Config: &cfg,
45                         eventSource: &pgEventSource{
46                                 PgConfig:  cfg.Postgres,
47                                 QueueSize: cfg.ServerEventQueue,
48                         },
49                 },
50         }
51         log.Fatal(srv.ListenAndServe())
52 }