Beispiel #1
0
func main() {
	log.SetFlags(log.LstdFlags | log.Lmicroseconds)
	var (
		httpAddress  = flag.String("http.addr", ":8080", "HTTP listen address")
		historicData = flag.String("historic.data", "", "path to data directory")
		printVersion = flag.Bool("version", false, "print version and exit")
	)
	flag.Parse()

	if *printVersion {
		fmt.Printf("%s", Version)
		os.Exit(0)
	}

	cache, err := populateExchangeRateCache(*historicData)
	if err != nil {
		log.Fatalf("Unable to populate cache: %v", err)
	}

	go func() {
		for {
			time.Sleep(6 * time.Hour)

			updateExchangeRatesCache(cache)
		}
	}()

	log.Printf("listening on %v", *httpAddress)
	log.Fatal(http.ListenAndServe(*httpAddress, logHandler(http.Handler(rateHTTP.Handler(cache)))))
}
Beispiel #2
0
func TestMain(m *testing.M) {
	cache, err := populateExchangeRateCache("data/eurofxref-hist.xml")
	if err != nil {
		log.Fatalf("Unable to populate cache: %v\n", err)
	}

	TestServer = testServer{
		server: httptest.NewServer(http.Handler(rateHTTP.Handler(cache))),
	}
	ret := m.Run()
	os.Exit(ret)
}