Added an automatic assets folder creator, fixed some naming issues
This commit is contained in:
parent
f5738e39f5
commit
ff59c394f4
4 changed files with 33 additions and 1 deletions
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
/assets/
|
||||
/assets/*
|
||||
.env
|
|
@ -19,7 +19,7 @@ func UploadFile(c *gin.Context) {
|
|||
}
|
||||
|
||||
f := models.File{
|
||||
Location: path,
|
||||
FileName: path,
|
||||
}
|
||||
|
||||
result := initializers.DB.Create(&f)
|
||||
|
|
28
initializers/assets.go
Normal file
28
initializers/assets.go
Normal file
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
1
main.go
1
main.go
|
@ -11,6 +11,7 @@ import (
|
|||
|
||||
func init() {
|
||||
initializers.LoadEnv()
|
||||
initializers.CreateAssetsFolder()
|
||||
initializers.ConnectToDB()
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue