Skip to content

Commit

Permalink
adding a MainErr function to nsqlookupd, for package importers to get…
Browse files Browse the repository at this point in the history
… error info

fixes #1003
  • Loading branch information
Stephen Searles committed Mar 2, 2018
1 parent e6debab commit ef17ac6
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions nsqlookupd/nsqlookupd.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package nsqlookupd

import (
"fmt"
"log"
"net"
"os"
Expand Down Expand Up @@ -42,13 +43,23 @@ func New(opts *Options) *NSQLookupd {
return n
}

// Main runs the service and calls os.Exit(1) if an error occurs.
func (l *NSQLookupd) Main() {
err := l.MainErr()
if err != nil {
l.logf(LOG_FATAL, "%v", err)
os.Exit(1)
}
}

// MainErr returns an error immediately if there was a problem starting up, but
// otherwise blocks indefinitely until Exit is called.
func (l *NSQLookupd) MainErr() error {
ctx := &Context{l}

tcpListener, err := net.Listen("tcp", l.opts.TCPAddress)
if err != nil {
l.logf(LOG_FATAL, "listen (%s) failed - %s", l.opts.TCPAddress, err)
os.Exit(1)
return fmt.Errorf("listen (%s) failed - %s", l.opts.TCPAddress, err)
}
l.Lock()
l.tcpListener = tcpListener
Expand All @@ -60,8 +71,7 @@ func (l *NSQLookupd) Main() {

httpListener, err := net.Listen("tcp", l.opts.HTTPAddress)
if err != nil {
l.logf(LOG_FATAL, "listen (%s) failed - %s", l.opts.HTTPAddress, err)
os.Exit(1)
return fmt.Errorf("listen (%s) failed - %s", l.opts.TCPAddress, err)
}
l.Lock()
l.httpListener = httpListener
Expand All @@ -70,6 +80,8 @@ func (l *NSQLookupd) Main() {
l.waitGroup.Wrap(func() {
http_api.Serve(httpListener, httpServer, "HTTP", l.logf)
})

return nil
}

func (l *NSQLookupd) RealTCPAddr() *net.TCPAddr {
Expand Down

0 comments on commit ef17ac6

Please sign in to comment.