Esempio n. 1
0
func main() {
	cf := flag.String("config", "restmqd.xml", "set config file")
	flag.Parse()
	if err := ReadConfig(*cf, &cfg); err != nil {
		log.Fatal(err)
	}
	queues = NewQueueGroup()
	// Use all CPUs available.
	numCPU := runtime.NumCPU()
	label := "CPU"
	if numCPU > 1 {
		label += "s"
	}
	runtime.GOMAXPROCS(numCPU)
	log.Printf("restmqd v%s (%d %s)", VERSION, numCPU, label)
	// Create the global RestMQ instance.
	rmq = restmq.New("127.0.0.1:6379")
	// HTTP handlers
	remux.HandleFunc("^/$", IndexHandler)
	qn := "([a-zA-Z0-9]+)$"
	remux.HandleFunc("^/q/"+qn, QueueHandler)
	remux.HandleFunc("^/c/"+qn, CometQueueHandler)
	//remux.HandleFunc("^/ws/"+qn, WebSocketQueueHandler)
	http.Handle("/ws/", websocket.Handler(WebSocketQueueHandler))
	server := http.Server{
		Handler: httpxtra.Handler{
			Handler: remux.DefaultServeMux,
			Logger:  logger,
		},
	}
	wg := &sync.WaitGroup{}
	if cfg.Addr != "" {
		wg.Add(1)
		http := server
		http.Addr = cfg.Addr
		log.Printf("Starting HTTP server on %s", http.Addr)
		go func() {
			log.Fatal(http.ListenAndServe())
			wg.Done()
		}()
	}
	if cfg.SSL.Addr != "" {
		wg.Add(1)
		https := server
		https.Addr = cfg.SSL.Addr
		log.Printf("Starting HTTPS server on %s", https.Addr)
		go func() {
			log.Fatal(https.ListenAndServeTLS(
				cfg.SSL.CertFile, cfg.SSL.KeyFile))
			wg.Done()
		}()

	}
	wg.Wait()
}
Esempio n. 2
0
func main() {
	redis_client = redis.New("127.0.0.1:6379")

	queue_name_re := "([a-zA-Z0-9]+)$"
	remux.HandleFunc("^/$", IndexHandler)
	remux.HandleFunc("^/q/"+queue_name_re, queueHandler)
	server := http.Server{
		Addr:    ":8080",
		Handler: remux.DefaultServeMux,
		Logger:  logger,
	}
	server.ListenAndServe()

}
Esempio n. 3
0
func main() {
	title_re := "([a-zA-Z0-9]+)$"
	remux.HandleFunc("^/$", IndexHandler)
	remux.HandleFunc("^/view/"+title_re, viewHandler)
	remux.HandleFunc("^/edit/"+title_re, editHandler)
	remux.HandleFunc("^/save/"+title_re, saveHandler)
	handler := httpxtra.Handler{
		Logger:  logger,
		Handler: remux.DefaultServeMux,
	}
	s := http.Server{
		Addr:    ":8080",
		Handler: handler,
	}
	log.Fatal(s.ListenAndServe())
}
Esempio n. 4
0
func main() {
	remux.HandleFunc("^/$", IndexHandler)
	remux.HandleFunc("^/static/(.*)$", StaticHandler)
	remux.HandleFunc("^/(crossdomain.xml)$", StaticHandler)
	remux.HandleFunc("^/(csv|json|xml)/(.*)$", makeHandler())
	server := http.Server{
		Addr:         listenOn,
		Handler:      remux.DefaultServeMux,
		Logger:       logger,
		ReadTimeout:  15 * time.Second,
		WriteTimeout: 15 * time.Second,
	}
	log.Println("FreeGeoIP server starting")
	if e := server.ListenAndServe(); e != nil {
		log.Println(e.Error())
	}
}