diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c308c3b --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +/assets/ +/assets/* +.env \ No newline at end of file diff --git a/controllers/fileController.go b/controllers/fileController.go index 7e98faf..81d968b 100644 --- a/controllers/fileController.go +++ b/controllers/fileController.go @@ -19,7 +19,7 @@ func UploadFile(c *gin.Context) { } f := models.File{ - Location: path, + FileName: path, } result := initializers.DB.Create(&f) diff --git a/initializers/assets.go b/initializers/assets.go new file mode 100644 index 0000000..d858687 --- /dev/null +++ b/initializers/assets.go @@ -0,0 +1,28 @@ +package initializers + +import ( + "log" + "os" +) + +func CreateAssetsFolder() { + + if _, err := os.Stat("assets/images"); os.IsNotExist(err) { + if err := os.MkdirAll("assets/images", os.ModePerm); err != nil { + log.Fatal(err) + } + } + + if _, err := os.Stat("assets/audios"); os.IsNotExist(err) { + if err := os.MkdirAll("assets/audios", os.ModePerm); err != nil { + log.Fatal(err) + } + } + + if _, err := os.Stat("assets/videos"); os.IsNotExist(err) { + if err := os.MkdirAll("assets/videos", os.ModePerm); err != nil { + log.Fatal(err) + } + } + +} diff --git a/main.go b/main.go index 1aedc0e..8c28a2e 100644 --- a/main.go +++ b/main.go @@ -11,6 +11,7 @@ import ( func init() { initializers.LoadEnv() + initializers.CreateAssetsFolder() initializers.ConnectToDB() }