Exemplo n.º 1
0
func run() error {
	kingpin.Parse()

	db, err := newDB()
	if err != nil {
		return errgo.Mask(err)
	}
	keyPair, err := loadKeyPair()
	if err != nil {
		return errgo.Mask(err)
	}
	service := boltstorage.NewService(db)
	handler := sfhttp.NewHandler(keyPair, service)

	r := httprouter.New()
	handler.Register(r)

	var t tomb.Tomb
	if *httpFlag != "" {
		t.Go(func() error {
			return http.ListenAndServe(*httpFlag, r)
		})
	}
	if *httpsFlag != "" && *certFlag != "" && *keyFlag != "" {
		t.Go(func() error {
			return http.ListenAndServeTLS(*httpsFlag, *certFlag, *keyFlag, r)
		})
	}

	log.Printf("public key: %s", keyPair.PublicKey.Encode())
	return t.Wait()
}
Exemplo n.º 2
0
func (s *boltHandlerSuite) SetUpTest(c *gc.C) {
	dir := c.MkDir()
	db, err := bolt.Open(filepath.Join(dir, "testdb"), 0600, nil)
	c.Assert(err, gc.IsNil)
	s.HTTPHandlerSuite.SetStorage(sfbolt.NewService(db))
	s.HTTPHandlerSuite.SetUpTest(c)
}