Example #1
0
func main() {

	var i_am = utilities.PrintGreeting(os.Stdout)
	var accepting_args = " <web root> <port>"
	if len(os.Args) < 3 {
		println(i_am + accepting_args)
		os.Exit(-1)
	}

	var root = os.Args[1]
	port, portErr := strconv.ParseInt(os.Args[2], 0, 16)

	if portErr != nil {
		println(i_am + " not happy with port argument " + os.Args[2] + " should be a 16-bit in [0;65535].")
		os.Exit(-2)
	}

	var clientApi = clientapi.New(root, int(port))
	var events = clientApi.GetEvent()
	var curDir, _ = os.Getwd()
	println(i_am + " Client API serving " + root + " at :" + strconv.Itoa(int(port)) + " from directory " + curDir)

	//
	// The ClientApi server implements the {Health} interface.
	// For now we simple listens for events and prints these to the log.
	// The EK_DOWN event makes us shutdown.
	//
	for {

		select {
		case e := <-events:
			if e.GetKind() == mtacontainer.EK_FATAL {
				return
			} else {
				log.Println(e.GetError().Error())
			}
		}
	}
	println(i_am + " leaving, bye")
}
Example #2
0
func main() {

	//
	// say hello
	//
	utilities.PrintGreeting(os.Stdout)

	//
	// Initialize logger for stdout for this mtaserver.
	//
	log := utilities.GetLogger("mtaserver")
	log.Print("Initial logger created, hi Log ")

	//
	// Start Container (ask for passphrase if necessary)
	//
	var container, _ = GetProductionMTAContainer()
	//var container, scheduler = GetLoopBackContainer();

	//
	// Print Events that occurs until GOOD_BYE.
	//
	for {
		e := <-container.GetEvent()
		log.Println(e.GetError())
		if e.GetKind() == mtacontainer.EK_GOOD_BYE {
			break
		}

		if e.GetKind() == mtacontainer.EK_INFORM_USER {
			postUserMessageWithClientAPI(e.GetError().Error(), e.GetPayload().(string))
		}
	}

	return
}