Repository: nsqio/nsq
File: apps/nsqlookupd/nsqlookupd.go (Go)

Code before:
package main

import (
	"flag"
	"fmt"
	"github.com/BurntSushi/toml"
	"github.com/bitly/nsq/util"
        nsqld "github.com/bitly/nsq/nsqlookupd"
	"log"
	"os"
	"os/signal"
	"syscall"
	"time"
)

var (
	flagSet = flag.NewFlagSet("nsqlookupd", flag.ExitOnError)

	config      = flagSet.String("config", "", "path to config file")
	showVersion = flagSet.Bool("version", false, "print version string")
	verbose     = flagSet.Bool("verbose", false, "enable verbose logging")

	tcpAddress       = flagSet.String("tcp-address", "0.0.0.0:4160", "<addr>:<port> to listen on for TCP clients")
	httpAddress      = flagSet.String("http-address", "0.0.0.0:4161", "<addr>:<port> to listen on for HTTP clients")
	broadcastAddress = flagSet.String("broadcast-address", "", "address of this lookupd node, (default to the OS hostname)")

	inactiveProducerTimeout = flagSet.Duration("inactive-producer-timeout", 300*time.Second, "duration of time a producer will remain in the active list since its last ping")
	tombstoneLifetime       = flagSet.Duration("tombstone-lifetime", 45*time.Second, "duration of time a producer will remain tombstoned if registration remains")
)

func main() {
	flagSet.Parse(os.Args[1:])

	if *showVersion {
		fmt.Println(util.Version("nsqlookupd"))
		return
	}

	signalChan := make(chan os.Signal, 1)
	exitChan := make(chan int)
	go func() {
		<-signalChan
		exitChan <- 1
	}()
	signal.Notify(signalChan, syscall.SIGINT, syscall.SIGTERM)

	var cfg map[string]interface{}
	if *config != "" {
		_, err := toml.DecodeFile(*config, &cfg)
		if err != nil {
			log.Fatalf("ERROR: failed to load config file %s - %s", *config, err.Error())
		}
	}

	options := nsqld.NewNSQLookupdOptions()
	util.ResolveOptions(options, flagSet, cfg)
	nsqlookupd := nsqld.NewNSQLookupd(options)

	log.Println(util.Version("nsqlookupd"))

	nsqlookupd.Main()
	<-exitChan
	nsqlookupd.Exit()
}



Review comment (suggestion):
I would prefer not to rename the import... can we resolve the conflict by changing whatever this conflicted with?

(if it's the variable name for the instance of the daemon, let's call it `daemon`?)


Code after:
package main

import (
	"flag"
	"fmt"
	"github.com/BurntSushi/toml"
	"github.com/bitly/nsq/util"
	"github.com/bitly/nsq/nsqlookupd"
	"log"
	"os"
	"os/signal"
	"syscall"
	"time"
)

var (
	flagSet = flag.NewFlagSet("nsqlookupd", flag.ExitOnError)

	config      = flagSet.String("config", "", "path to config file")
	showVersion = flagSet.Bool("version", false, "print version string")
	verbose     = flagSet.Bool("verbose", false, "enable verbose logging")

	tcpAddress       = flagSet.String("tcp-address", "0.0.0.0:4160", "<addr>:<port> to listen on for TCP clients")
	httpAddress      = flagSet.String("http-address", "0.0.0.0:4161", "<addr>:<port> to listen on for HTTP clients")
	broadcastAddress = flagSet.String("broadcast-address", "", "address of this lookupd node, (default to the OS hostname)")

	inactiveProducerTimeout = flagSet.Duration("inactive-producer-timeout", 300*time.Second, "duration of time a producer will remain in the active list since its last ping")
	tombstoneLifetime       = flagSet.Duration("tombstone-lifetime", 45*time.Second, "duration of time a producer will remain tombstoned if registration remains")
)

func main() {
	flagSet.Parse(os.Args[1:])

	if *showVersion {
		fmt.Println(util.Version("nsqlookupd"))
		return
	}

	signalChan := make(chan os.Signal, 1)
	exitChan := make(chan int)
	go func() {
		<-signalChan
		exitChan <- 1
	}()
	signal.Notify(signalChan, syscall.SIGINT, syscall.SIGTERM)

	var cfg map[string]interface{}
	if *config != "" {
		_, err := toml.DecodeFile(*config, &cfg)
		if err != nil {
			log.Fatalf("ERROR: failed to load config file %s - %s", *config, err.Error())
		}
	}

	options := nsqlookupd.NewNSQLookupdOptions()
	util.ResolveOptions(options, flagSet, cfg)
	daemon := nsqlookupd.NewNSQLookupd(options)

	log.Println(util.Version("nsqlookupd"))

	daemon.Main()
	<-exitChan
	daemon.Exit()
}