Fixed a lot of stuff
This commit is contained in:
parent
9d947e1e37
commit
46a52dd1d7
4 changed files with 32 additions and 20 deletions
|
@ -12,7 +12,7 @@ services:
|
||||||
JWT_SECRET: "${JWT_SECRET}"
|
JWT_SECRET: "${JWT_SECRET}"
|
||||||
GIN_MODE: "${GIN_MODE}"
|
GIN_MODE: "${GIN_MODE}"
|
||||||
volumes:
|
volumes:
|
||||||
- assets:/app/assets
|
- ./assets:/data/assets
|
||||||
|
|
||||||
volumes:
|
volumes:
|
||||||
assets:
|
assets:
|
|
@ -5,22 +5,19 @@ import (
|
||||||
"os"
|
"os"
|
||||||
)
|
)
|
||||||
|
|
||||||
func CreateAssetsFolder() {
|
var DebugBasePath string = "./assets/"
|
||||||
|
var ReleaseBasePath string = "/data/assets/"
|
||||||
|
|
||||||
if _, err := os.Stat("assets/images"); os.IsNotExist(err) {
|
func CreateAssetsFolder(basePath string) {
|
||||||
if err := os.MkdirAll("assets/images", os.ModePerm); err != nil {
|
|
||||||
|
if _, err := os.Stat(basePath + "images"); os.IsNotExist(err) {
|
||||||
|
if err := os.MkdirAll(basePath+"images", os.ModePerm); err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := os.Stat("assets/audios"); os.IsNotExist(err) {
|
if _, err := os.Stat(basePath + "videos"); os.IsNotExist(err) {
|
||||||
if err := os.MkdirAll("assets/audios", os.ModePerm); err != nil {
|
if err := os.MkdirAll(basePath+"videos", 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)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,14 +1,18 @@
|
||||||
package initializers
|
package initializers
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/joho/godotenv"
|
|
||||||
"log"
|
"log"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"github.com/joho/godotenv"
|
||||||
)
|
)
|
||||||
|
|
||||||
func LoadEnv() {
|
func LoadEnv() {
|
||||||
|
if os.Getenv("GIN_MODE") != "release" {
|
||||||
err := godotenv.Load()
|
err := godotenv.Load()
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal("Error loading .env file!")
|
log.Fatal("Error loading .env file!")
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
17
main.go
17
main.go
|
@ -10,9 +10,16 @@ import (
|
||||||
"os"
|
"os"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var currentMode string
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
initializers.LoadEnv()
|
initializers.LoadEnv()
|
||||||
initializers.CreateAssetsFolder()
|
currentMode = os.Getenv("GIN_MODE")
|
||||||
|
if currentMode == "debug" {
|
||||||
|
initializers.CreateAssetsFolder(initializers.DebugBasePath)
|
||||||
|
} else {
|
||||||
|
initializers.CreateAssetsFolder(initializers.ReleaseBasePath)
|
||||||
|
}
|
||||||
initializers.ConnectToDB()
|
initializers.ConnectToDB()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,9 +37,13 @@ func main() {
|
||||||
api.Api.GET("/users/:id", controllers.GetUserById)
|
api.Api.GET("/users/:id", controllers.GetUserById)
|
||||||
|
|
||||||
// Files
|
// Files
|
||||||
api.Router.Static("assets", "./assets/images")
|
if currentMode == "debug" {
|
||||||
|
api.Router.Static("assets", initializers.DebugBasePath+"/images")
|
||||||
|
} else {
|
||||||
|
api.Router.Static("assets", initializers.ReleaseBasePath+"/images")
|
||||||
|
}
|
||||||
|
|
||||||
// Posts (middleware to add)
|
// Posts
|
||||||
api.Api.POST("/posts", middleware.RequireAuth, controllers.CreatePost)
|
api.Api.POST("/posts", middleware.RequireAuth, controllers.CreatePost)
|
||||||
|
|
||||||
// Starting
|
// Starting
|
||||||
|
|
Loading…
Add table
Reference in a new issue