96 lines
2.4 KiB
Go
96 lines
2.4 KiB
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"log"
|
|
"os"
|
|
|
|
"personalwebsite/apps"
|
|
blogwriter "personalwebsite/apps/BlogWriter"
|
|
"personalwebsite/apps/blogviewer"
|
|
"personalwebsite/apps/finder"
|
|
imgviewer "personalwebsite/apps/img-viewer"
|
|
"personalwebsite/apps/personalprops"
|
|
"personalwebsite/routes"
|
|
"personalwebsite/wde"
|
|
"personalwebsite/webfilesystem"
|
|
|
|
"github.com/joho/godotenv"
|
|
"go.mongodb.org/mongo-driver/mongo"
|
|
"go.mongodb.org/mongo-driver/mongo/options"
|
|
)
|
|
|
|
func main() {
|
|
if err := godotenv.Load(); err != nil {
|
|
println("No .env file found")
|
|
}
|
|
|
|
mongoConnect, err := FindEnv("MONGO_CONNECT")
|
|
if err != nil {
|
|
panic(err.Error())
|
|
}
|
|
|
|
dBName, err := FindEnv("DATABASE")
|
|
if err != nil {
|
|
panic(err.Error())
|
|
}
|
|
|
|
webFsCollection, err := FindEnv("COLLECTION_WEBFS")
|
|
if err != nil {
|
|
panic(err.Error())
|
|
}
|
|
|
|
publicPort, err := FindEnv("PUBLIC_PORT")
|
|
if err != nil {
|
|
panic(err.Error())
|
|
}
|
|
|
|
privatePort, err := FindEnv("PRIVATE_PORT")
|
|
if err != nil {
|
|
panic(err.Error())
|
|
}
|
|
|
|
clientOptions := options.Client().ApplyURI(mongoConnect)
|
|
client, err := mongo.Connect(context.TODO(), clientOptions)
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
err = client.Ping(context.TODO(), nil)
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
|
|
webfs := webfilesystem.NewWebFileSystem(client, dBName, webFsCollection)
|
|
appsStorage := apps.NewApplicationsStorage(map[string]apps.WebDEApplication{}, webfs)
|
|
|
|
webde := wde.NewWDE(webfs)
|
|
|
|
//TODO Split to different apps init for private and public?
|
|
persPropsApp := personalprops.NewPersPropsApp(webfs)
|
|
finderApp := finder.NewFinderApplication(webfs)
|
|
imgViewerApp := imgviewer.NewImgViewerApp(webfs)
|
|
blogViewerApp := blogviewer.NewBlogViewerApp(webfs)
|
|
blogWriterApp := blogwriter.NewBlogWriterApp(webfs)
|
|
appsStorage.Apps["personal-properties"] = persPropsApp
|
|
appsStorage.Apps["finder"] = finderApp
|
|
appsStorage.Apps["img-viewer"] = imgViewerApp
|
|
appsStorage.Apps[blogViewerApp.GetAppID()] = blogViewerApp
|
|
appsStorage.Apps["BlogWriter"] = blogWriterApp
|
|
|
|
go routes.PublicRoutes(publicPort, webfs, webde, appsStorage)
|
|
routes.PrivateRoutes(privatePort, webfs, webde, appsStorage)
|
|
}
|
|
|
|
func FindEnv(parameter string) (string, error) {
|
|
path, exists := os.LookupEnv(parameter)
|
|
|
|
if exists {
|
|
println("[ENV] Requsted " + parameter + " = " + path) //FIXME Only in Debug log
|
|
return path, nil
|
|
} else {
|
|
panic("[ENV] Requsted " + parameter + " not found")
|
|
return "", errors.New("env parameter not found")
|
|
}
|
|
}
|