Ejemplo n.º 1
0
func runHTTPListeners(d db.DB) {
	httpMux, err := api.Routes(source)
	if err != nil {
		log.Fatalf("router setup failed: %s\n", err.Error())
	}

	httpsMux, err := api.Routes(
		api.Admin(d),
		api.User(d),
		api.Task(d),
	)
	if err != nil {
		log.Fatalf("router setup failed: %s\n", err.Error())
	}

	var (
		httpErr  = make(chan error)
		httpsErr = make(chan error)
	)

	log.Printf("mf-proto hosting source on HTTP 25000")
	log.Printf("mf-proto listening on HTTPS 25001")

	go func() { httpsErr <- http.ListenAndServeTLS(":25001", "cert.pem", "key.key", httpsMux) }()
	go func() { httpErr <- http.ListenAndServe(":25000", httpMux) }()

	go func() {
		var e error
		select {
		case e = <-httpErr:
		case e = <-httpsErr:
		}
		log.Fatalf("error serving http(s): %s", e.Error())
	}()
}
Ejemplo n.º 2
0
func runHTTPListeners(d db.DB) {
	httpMux := htr.New()
	httpsMux := htr.New()

	// httpMux.SetupRoutes()
	err := api.SetupRoutes(
		httpsMux,
		api.Auth(d),
		api.User(d),
		api.Task(d),
	)

	if err != nil {
		log.Fatalf("router setup failed: %s\n", err.Error())
	}

	var (
		httpErr  = make(chan error)
		httpsErr = make(chan error)
	)

	println("Listening on HTTP 25000")
	println("Listening on HTTPS 25001")

	go func() { httpErr <- http.ListenAndServeTLS(":25001", "cert.pem", "key.key", httpsMux) }()
	go func() { httpsErr <- http.ListenAndServe(":25000", httpMux) }()

	var e error
	select {
	case e = <-httpErr:
	case e = <-httpsErr:
	}
	log.Fatalf("error serving http(s): %s", e.Error())
}