Exemplo n.º 1
0
func startHoarder(ccmd *cobra.Command, args []string) error {
	// convert the log level
	logLvl := lumber.LvlInt(viper.GetString("log-level"))

	// configure the logger
	lumber.Prefix("[hoader]")
	lumber.Level(logLvl)

	// enable/start garbage collection if age config was changed
	if ccmd.Flag("clean-after").Changed {
		lumber.Debug("Starting garbage collector (data older than %vs)...\n", ccmd.Flag("clean-after").Value)

		// start garbage collector
		go collector.Start()
	}

	// set, and initialize, the backend driver
	if err := backends.Initialize(); err != nil {
		lumber.Error("Failed to initialize backend - %v", err)
		return err
	}

	// start the API
	if err := api.Start(); err != nil {
		lumber.Fatal("Failed to start API: ", err.Error())
		return err
	}

	return nil
}
Exemplo n.º 2
0
func TestMain(m *testing.M) {

	// manually configure
	http.DefaultTransport.(*http.Transport).TLSClientConfig = &tls.Config{InsecureSkipVerify: true}
	viper.Set("backend", "file:///tmp/hoarder_test")
	viper.Set("listen-addr", testAddr)
	viper.Set("token", "secret")
	lumber.Level(lumber.LvlInt("fatal"))

	// empty test dir
	os.RemoveAll("/tmp/hoarder_test")
	backends.Initialize()
	// start api
	go api.Start()
	<-time.After(time.Second)
	rtn := m.Run()

	// empty test dir
	os.RemoveAll("/tmp/hoarder_test")

	os.Exit(rtn)
}