package main

import (
	"flag"
	"fmt"
)

var UniqueId string
var heartbeatChan chan bool

func processCommandLineArguments() (int, int, error) {
	var hostId = flag.Int("hostId", 0, "The unique id for the host.")
	var port = flag.Int("port", 0, "The per-host unique port")

	flag.Parse()

	if *hostId == 0 || *port == 0 {
		return 0, 0,
			fmt.Errorf("Cannot proceed with hostId %d and port %d\n"+
				"Usage: ./identity -hostId hostId -port port", *hostId, *port)
	}
	return *hostId, *port, nil
}

func getMyUniqueId() string {
	return UniqueId
}

func main() {
	hostId, port, err := processCommandLineArguments()
	if err != nil {
		fmt.Println("Problem parsing arguments:", err)
		return
	}
	heartbeatChan = make(chan bool)
	UniqueId = fmt.Sprintf("%d_%d", hostId, port)
	err = initLogger()
	if err != nil {
		fmt.Println("Problem opening file", err)
		return
	}
	stateMachineInit()
	nodeInit()
	parseConfig()
	err = startServer(port)
	if err != nil {
		fmt.Println("Problem starting server", err)
		return
	}
}

package main

import (
	"flag"
	"fmt"
	"log"
)

var UniqueId string
var heartbeatChan chan bool

func processCommandLineArguments() (int, int, error) {
	var hostId = flag.Int("hostId", 0, "The unique id for the host.")
	var port = flag.Int("port", 0, "The per-host unique port")

	flag.Parse()

	if *hostId == 0 || *port == 0 {
		return 0, 0,
			fmt.Errorf("Cannot proceed with hostId %d and port %d\n"+
				"Usage: ./identity -hostId hostId -port port", *hostId, *port)
	}
	return *hostId, *port, nil
}

func getMyUniqueId() string {
	return UniqueId
}

func main() {
	hostId, port, err := processCommandLineArguments()
	if err != nil {
		fmt.Println("Problem parsing arguments:", err)
		return
	}
	heartbeatChan = make(chan bool)
	UniqueId = fmt.Sprintf("%d_%d", hostId, port)
	err = initLogger()
	if err != nil {
		fmt.Println("Problem opening file", err)
		return
	}
	stateMachineInit()
	nodeInit()
	parseConfig()
	if findNode(UniqueId) != nil {
		log.Fatal("Could not find myself in the config: ", UniqueId)
	}
	err = startServer(port)
	if err != nil {
		fmt.Println("Problem starting server", err)
		return
	}
}

Make sure we are part of the config.
Make sure we are part of the config.
