diff --git a/cmd/dogtamer.go b/cmd/dogtamer.go index 5fc4c50..58dcc6a 100644 --- a/cmd/dogtamer.go +++ b/cmd/dogtamer.go @@ -66,24 +66,25 @@ func ActionServe(c *cli.Context) error { } // Setup proper logger logger = setupServerLogger(cfg.LogLevel) + cfg.DebugLog(logger) ctx, cancel := context.WithCancel(context.Background()) // Setup RTMP-server - s := server.NewRTMPServer(ctx, cfg.RTMPListenAddr) - s.Logger = logger - s.Hostname = cfg.Hostname + rtmpServer := server.NewRTMPServer(ctx, cfg.RTMPListenAddr) + rtmpServer.Logger = logger + rtmpServer.Hostname = cfg.Hostname // Setup web-server webDone := make(chan struct{}) if cfg.HTTPServerEnable { - ws := server.NewWebServer(ctx, s) + ws := server.NewWebServer(ctx, rtmpServer) ws.ListenAddr = cfg.HTTPListenAddr ws.Logger = logger go func() { - s.Logger.Infow("Starting HTTP server.", "listen_addr", ws.ListenAddr) + rtmpServer.Logger.Infow("Starting HTTP server.", "listen_addr", ws.ListenAddr) err := ws.Serve() if err != nil && err != http.ErrServerClosed { - s.Logger.Infow("HTTP server shut down with error.", "err", err) + rtmpServer.Logger.Infow("HTTP server shut down with error.", "err", err) } close(webDone) }() @@ -95,19 +96,19 @@ func ActionServe(c *cli.Context) error { signal.Notify(sigChan, os.Interrupt) go func() { <-sigChan - s.Logger.Debug("Got shutdown signal.") + rtmpServer.Logger.Debug("Got shutdown signal.") cancel() }() // Start RTMP-server - s.Logger.Infow("Starting RTMP server.", "listen_addr", s.ListenAddr) - if err := s.Listen(); err != nil { + rtmpServer.Logger.Infow("Starting RTMP server.", "listen_addr", s.ListenAddr) + if err := rtmpServer.Listen(); err != nil { return cli.Exit(err, ExitGenericError) } // Wait for webserver to exit, if started <-webDone - s.Logger.Info("Server shut down.") + rtmpServer.Logger.Info("Server shut down.") return nil } diff --git a/config/config.go b/config/config.go index cc04f35..4fe16ac 100644 --- a/config/config.go +++ b/config/config.go @@ -9,6 +9,7 @@ import ( "strings" "github.com/pelletier/go-toml" + "go.uber.org/zap" ) var ErrNotFound = errors.New("no config file found") @@ -131,3 +132,12 @@ func FromDefaultLocations() (*Config, error) { } return nil, ErrNotFound } + +func (c *Config) DebugLog(logger *zap.SugaredLogger) { + logger.Debugw("Config", + "hostname", c.Hostname, + "rtmp_addr", c.RTMPListenAddr, + "http_enable", c.HTTPListenAddr, + "http_accesslog", c.HTTPAccessLogEnable, + "log_level", c.LogLevel) +} diff --git a/config/config_test.go b/config/config_test.go index bbe5e7a..4f314ed 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -122,7 +122,8 @@ func TestConfig(t *testing.T) { sr := strings.NewReader(emptyCfg) c, err := config.FromReader(sr) - if err != nil { + if err == nil { + // TODO: Check that it actually returns the correct error t.Fatalf("Error parsing config string: %s", err) } if err := c.UpdateFromEnv(); err == nil { diff --git a/server/rtmp.go b/server/rtmp.go index 9ef3e13..3b60ba9 100644 --- a/server/rtmp.go +++ b/server/rtmp.go @@ -369,25 +369,25 @@ type StreamInfo struct { Path string } -func (s *RTMPServer) List() []*StreamInfo { +func (rs *RTMPServer) List() []*StreamInfo { var results []*StreamInfo - _, port, _ := net.SplitHostPort(s.ListenAddr) + _, port, _ := net.SplitHostPort(rs.ListenAddr) - for _, stream := range s.streams { - results = append(results, &StreamInfo{Name: stream.Name, Path: fmt.Sprintf("rtmp://%s:%s/view/%s", s.Hostname, port, stream.Name)}) + for _, stream := range rs.streams { + results = append(results, &StreamInfo{Name: stream.Name, Path: fmt.Sprintf("rtmp://%s:%s/view/%s", rs.Hostname, port, stream.Name)}) } return results } -func (s *RTMPServer) GetInfo(name string) (*StreamInfo, error) { - stream, ok := s.streams[name] +func (rs *RTMPServer) GetInfo(name string) (*StreamInfo, error) { + stream, ok := rs.streams[name] if !ok { return nil, ErrNoSuchItem } - _, port, _ := net.SplitHostPort(s.ListenAddr) + _, port, _ := net.SplitHostPort(rs.ListenAddr) return &StreamInfo{ Name: stream.Name, - Path: fmt.Sprintf("rtmp://%s:%s/view/%s", s.Hostname, port, stream.Name), + Path: fmt.Sprintf("rtmp://%s:%s/view/%s", rs.Hostname, port, stream.Name), }, nil }