Ejemplo n.º 1
0
func getConnection() *gorm.DB {
	db, err := gorm.Open("postgres", "postgres://category_service-go:@127.0.0.1:5432/category_service-go?sslmode=disable")
	if err != nil {
		l4g.Critical("Failed to open sql connection to err:%v", err)
		time.Sleep(time.Second)
		panic("Failed to open sql connection " + err.Error())
	}

	db.DB()

	l4g.Info("Pinging sql postgres database")
	err = db.DB().Ping()
	if err != nil {
		l4g.Critical("Failed to ping db err:%v", err)
		time.Sleep(time.Second)
		panic("Failed  to open sql connection " + err.Error())
	}

	db.DB().SetMaxIdleConns(10)
	db.DB().SetMaxOpenConns(100)

	return &db
}
Ejemplo n.º 2
0
func StartServer() {
	l4g.Info("Starting Server...")
	l4g.Info("Server is listening on " + os.Getenv("PORT"))

	go func() {
		err := Srv.Server.ListenAndServe()

		if err != nil {
			l4g.Critical("Error starting server, err:%v", err)
			time.Sleep(time.Second)
			panic("Error starting server " + err.Error())
		}
	}()
}