Commit d978cb5f authored by Lukas Böhm's avatar Lukas Böhm 🎱
Browse files

format

parent 697729af
......@@ -14,25 +14,25 @@ import (
// Share has many Attachments, ShareID is the foreign key
type Share struct {
ID uuid.UUID `json:"id" gorm:"type:uuid; primary_key"`
Name string `json:"name,omitempty"`
Expires *time.Time `json:"expires,omitempty"`
DownloadLimit uint `json:"download_limit,omitempty"`
IsPublic bool `json:"is_public" gorm:"not null; default:false; index"`
Password string `json:"-"`
Email string `json:"email,omitempty"`
IsTemporary bool `json:"-" gorm:"not null"`
ID uuid.UUID `json:"id" gorm:"type:uuid; primary_key"`
Name string `json:"name,omitempty"`
Expires *time.Time `json:"expires,omitempty"`
DownloadLimit uint `json:"download_limit,omitempty"`
IsPublic bool `json:"is_public" gorm:"not null; default:false; index"`
Password string `json:"-"`
Emails string `json:"email,omitempty"`
IsTemporary bool `json:"-" gorm:"not null"`
Attachments []Attachment`json:"files,omitempty" gorm:"constraint:OnDelete:CASCADE"`
Attachments []Attachment `json:"files,omitempty" gorm:"constraint:OnDelete:CASCADE"`
}
type Attachment struct {
ID uuid.UUID `json:"id" gorm:"type:uuid; primary_key"`
Filename string `json:"filename" gorm:"not null"`
Filesize int64 `json:"filesize" gorm:"not null; default:0"`
IsEncrypted bool `json:"-" gorm:"not null; default:false"`
ID uuid.UUID `json:"id" gorm:"type:uuid; primary_key"`
Filename string `json:"filename" gorm:"not null"`
Filesize int64 `json:"filesize" gorm:"not null; default:0"`
IsEncrypted bool `json:"-" gorm:"not null; default:false"`
ShareID uuid.UUID `json:"-" gorm:"not null"`
ShareID uuid.UUID `json:"-" gorm:"not null"`
}
func (sh *Share) BeforeCreate(scope *gorm.DB) error {
......@@ -73,14 +73,14 @@ func (att *Attachment) BeforeDelete(scope *gorm.DB) error {
return os.Remove(filepath.Join(config.mediaDir, "data", att.ShareID.String(), att.ID.String()))
}
func GetDatabase()(*gorm.DB, error) {
func GetDatabase() (*gorm.DB, error) {
dsn := os.Getenv("DATABASE_URI")
split := strings.SplitN(dsn, ":", 2)
if split[0] == "postgres" {
return gorm.Open(postgres.Open(dsn), &gorm.Config{})
} else if split[0] == "sqlserver" {
return gorm.Open(sqlserver.Open(dsn), &gorm.Config{})
} else if split[0] == "sqlite"{
} else if split[0] == "sqlite" {
return gorm.Open(sqlite.Open(dsn), &gorm.Config{})
}
return nil, nil
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment