diff --git a/source/services/database.go b/source/services/database.go new file mode 100644 index 0000000..f84e159 --- /dev/null +++ b/source/services/database.go @@ -0,0 +1,35 @@ +/** + * Created by fbonhomm + * Email: flo-github@outlook.fr + * Licence: MIT + */ + +package services + +import ( + "fmt" + "github.com/fbonhomm/api-go/source/models" + "github.com/jinzhu/gorm" + _ "github.com/jinzhu/gorm/dialects/postgres" + "log" + "os" +) + +var Db *gorm.DB +var Err error + +func Database() { + Db, Err = gorm.Open( + "postgres", + fmt.Sprintf( + "host=%s port=%s dbname=%s user=%s password=%s sslmode=disable", + os.Getenv("DB_HOST"), os.Getenv("DB_PORT"), os.Getenv("DB_NAME"), + os.Getenv("DB_USER"), os.Getenv("DB_PASSWORD")), + ) + + if Err != nil { + log.Panic("Error connect database: ", Err) + } + + Db.AutoMigrate(&models.User{}) +} diff --git a/source/services/load-key.go b/source/services/jwt.go similarity index 98% rename from source/services/load-key.go rename to source/services/jwt.go index d6c7419..daf383f 100644 --- a/source/services/load-key.go +++ b/source/services/jwt.go @@ -20,7 +20,7 @@ var PublicKeyRefresh *ecdsa.PublicKey var PrivateKeyRefresh *ecdsa.PrivateKey var err error -func init() { +func Jwt() { var tmp []byte tmp, _ = ioutil.ReadFile(ROOT + "/jwt/access.public.pem")