Exemple #1
0
func TestMain(m *testing.M) {
	log.SetFlags(log.LstdFlags | log.Llongfile)
	testConfig, err := config.ReadFile("../config_test.gcfg")
	testConfig.Website.Directory = "../" + testConfig.Website.Directory
	if err != nil {
		log.Println(err)
		os.Exit(1)
	}
	err = transactions.Init(testConfig)
	if err != nil {
		log.Println(err)
		os.Exit(1)
	}
	Init(testConfig)
	os.Exit(m.Run())

}
Exemple #2
0
func main() {
	log.SetFlags(log.LstdFlags | log.Llongfile)

	var err error
	mainConfig, err = config.ReadFile("config.gcfg")
	if err != nil {
		log.Fatal(err)
	}
	api.Init(mainConfig)
	types.Init(mainConfig)
	err = transactions.Init(mainConfig)
	if err != nil {
		log.Fatal(err)
	}

	r := mux.NewRouter()
	apiHandler, err := api.MakeHandler()
	if err != nil {
		log.Fatal(err)
	}
	r.HandleFunc("/", api.IndexHandler)
	r.PathPrefix("/api").Handler(http.StripPrefix("/api", apiHandler))
	r.PathPrefix("/").Handler(http.FileServer(http.Dir(mainConfig.Website.Directory)))
	http.Handle("/", r)
	go func() {
		log.Printf("Serving HTTP on %s\n", mainConfig.Website.HTTPPort)
		err := http.ListenAndServe(mainConfig.Website.HTTPPort, http.HandlerFunc(redirectHandler))
		if err != nil {
			log.Fatal(err)
		}
	}()
	log.Printf("Serving HTTPS on %s\n", mainConfig.Website.HTTPSPort)
	err = http.ListenAndServeTLS(mainConfig.Website.HTTPSPort, mainConfig.Website.Cert, mainConfig.Website.Key, nil)
	if err != nil {
		log.Fatal(err)
	}
}