Exemplo n.º 1
0
func main() {
	defer func() {
		r := recover()
		if r != nil {
			fmt.Println("got this from panic", r)
		} else {
			fmt.Println("got nothing from panic")
		}
	}()

	config := readConfig()

	http.Handle("/", http.FileServer(http.Dir(dirname()+"/"+staticDir+"/")))
	sockjsMux := sockjs.NewServeMux(http.DefaultServeMux)
	sockjsConf := sockjs.NewConfig()
	sockjsMux.Handle("/data", dataHandler, sockjsConf)

	geolocEvents := make(chan hpfeeds.Message)
	go hpfeedsConnect(config, geolocEvents)
	go broadcast(geolocEvents)

	log.Printf("Binding Honeymap webserver to %s...", bind)
	err := http.ListenAndServe(bind, sockjsMux)
	checkFatalError(err)
}
Exemplo n.º 2
0
func main() {
	http.Handle("/", http.FileServer(http.Dir("../../client/")))
	sockjsMux := sockjs.NewServeMux(http.DefaultServeMux)
	sockjsConf := sockjs.NewConfig()
	sockjsMux.Handle("/data", dataHandler, sockjsConf)

	go func() {
		for {
			lat := rand.Float32()*180 - 90
			lng := rand.Float32()*360 - 180
			sockjsClients.Broadcast([]byte(fmt.Sprintf("{ \"latitude\": %f, \"longitude\": %f }", lat, lng)))
			time.Sleep(100 * time.Millisecond)
		}
	}()

	log.Printf("Binding Honeymap webserver to %s...", bind)
	http.ListenAndServe(bind, sockjsMux)
}