Example #1
0
func main() {
	middleware := synapse.NewChain(
		NewRequestMiddleare(),
		TracingMiddleware(newTraceID),
		LoggingMiddleware(os.Stdout),
		AuthMiddleware(),
	)

	router := mux.NewRouter()

	router.Methods("GET").Path("/report").Handler(middleware.Then(NewGetReportHandler()))

	errCh := make(chan error)
	go func() {
		log.Println(`msg="starting webserver" bind=:9000`)
		errCh <- http.ListenAndServe(":9000", router)
	}()

	signalCh := make(chan os.Signal)
	signal.Notify(signalCh, os.Interrupt, os.Kill)

	select {
	case err := <-errCh:
		log.Printf(`msg="error occurred" err=%s\n`, err)
	case sig := <-signalCh:
		log.Printf(`msg="signal received" signal=%s`, sig.String())
	}
}
Example #2
0
func NewGetReportHandler() synapse.Handler {
	return synapse.NewChain(
		newReport(),
		defaultReport(),
	).Then(JSON(http.StatusOK, "report"))
}