Exemplo n.º 1
0
Arquivo: main.go Projeto: soygul/titan
func startServer(addr string) {
	s, err := titan.NewServer(addr)
	if err != nil {
		log.Fatalf("error creating server: %v", err)
	}

	if *awsFlag {
		s.SetDB(aws.NewDynamoDB("", ""))
	}

	defer func() {
		if s.Close(); err != nil {
			log.Printf("error closing server: %v", err)
		}
	}()

	if err := s.ListenAndServe(); err != nil {
		log.Fatalf("error listening for connections: %v", err)
	}
}
Exemplo n.º 2
0
// NewServerHelper creates a new server helper object.
// Titan server instance is initialized and ready to accept connection after this function return.
func NewServerHelper(t *testing.T) *ServerHelper {
	if testing.Short() {
		t.Skip("Skipping integration test in short testing mode")
	}

	if (titan.Conf == titan.Config{}) {
		titan.InitConf("test")
	}

	url := "127.0.0.1:" + titan.Conf.App.Port
	s, err := titan.NewServer(url)
	if err != nil {
		t.Fatal("Failed to create server:", err)
	}

	var db data.DB
	if *awsFlag {
		db = aws.NewDynamoDB("", "")
		if err := db.Seed(true, titan.Conf.App.JWTPass()); err != nil {
			t.Fatal("Failed to set seed DynamoDB:", err)
		}
	} else {
		db = inmem.NewDB()
	}
	if err := s.SetDB(db); err != nil {
		t.Fatal("Failed to set server database instance:", err)
	}

	h := ServerHelper{
		db:           db,
		server:       s,
		testing:      t,
		serverClosed: make(chan bool),
	}

	return &h
}