44 lines
824 B
Go
44 lines
824 B
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/jinzhu/gorm"
|
|
"github.com/joho/godotenv"
|
|
"github.com/labstack/gommon/log"
|
|
)
|
|
|
|
func main() {
|
|
err := godotenv.Load(".env")
|
|
if err != nil {
|
|
log.Fatalf("ENV file not found")
|
|
}
|
|
dbhost := os.Getenv("DB_HOST")
|
|
dbuser := os.Getenv("DB_USER")
|
|
dbpass := os.Getenv("DB_PASS")
|
|
dbdata := os.Getenv("DB_DATA")
|
|
|
|
connectionstring := fmt.Sprintf("host=%s user=%s password=%s dbname=%s sslmode=disable", dbhost, dbuser, dbpass, dbdata)
|
|
|
|
db, err := gorm.Open("postgres", connectionstring)
|
|
|
|
if err != nil {
|
|
panic(err.Error())
|
|
}
|
|
app := App{
|
|
db: db,
|
|
r: gin.Default(),
|
|
}
|
|
app.start()
|
|
//r := gin.Default()
|
|
|
|
}
|
|
|
|
/*func terminateWithError(statusCode int, message string, c *gin.Context) {
|
|
c.JSON(statusCode, gin.H{"error": message})
|
|
c.Abort()
|
|
}
|
|
*/
|