Ejemplo 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()
}
Ejemplo n.º 2
0
func (s *HTTPHandlerSuite) SetUpTest(c *gc.C) {
	c.Assert(s.service, gc.NotNil)

	r := httprouter.New()
	s.keyPair = MustNewKeyPair()
	s.handler = sfhttp.NewHandler(s.keyPair, s.service)
	s.handler.Register(r)
	s.server = httptest.NewServer(r)
	s.tlsServer = httptest.NewTLSServer(r)
}