2023-03-15 00:05:24 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2023-04-25 09:37:42 +00:00
|
|
|
"context"
|
|
|
|
"errors"
|
|
|
|
"os"
|
2023-11-24 19:12:13 +00:00
|
|
|
"personalwebsite/webfs"
|
2023-03-15 00:05:24 +00:00
|
|
|
|
2023-04-25 09:37:42 +00:00
|
|
|
"github.com/joho/godotenv"
|
2023-11-24 19:12:13 +00:00
|
|
|
"personalwebsite/routes"
|
2023-03-15 00:05:24 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2023-04-25 09:37:42 +00:00
|
|
|
if err := godotenv.Load(); err != nil {
|
|
|
|
println("No .env file found")
|
|
|
|
}
|
|
|
|
|
|
|
|
mongoConnect, err := FindEnv("MONGO_CONNECT")
|
|
|
|
if err != nil {
|
|
|
|
panic(err.Error())
|
|
|
|
}
|
2023-11-24 19:12:13 +00:00
|
|
|
//
|
2023-04-25 09:37:42 +00:00
|
|
|
dBName, err := FindEnv("DATABASE")
|
|
|
|
if err != nil {
|
|
|
|
panic(err.Error())
|
|
|
|
}
|
|
|
|
|
|
|
|
webFsCollection, err := FindEnv("COLLECTION_WEBFS")
|
|
|
|
if err != nil {
|
|
|
|
panic(err.Error())
|
|
|
|
}
|
2023-11-24 19:12:13 +00:00
|
|
|
//
|
|
|
|
//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 := aboutme.NewAboutMeApp(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)
|
|
|
|
ctx := context.Background()
|
|
|
|
//ctx.
|
|
|
|
err = webfs.Init(ctx, mongoConnect, dBName, webFsCollection)
|
2023-05-23 23:19:21 +00:00
|
|
|
if err != nil {
|
|
|
|
panic(err.Error())
|
|
|
|
}
|
|
|
|
|
2023-11-24 19:12:13 +00:00
|
|
|
routes.ApiRoutes()
|
2023-03-15 00:05:24 +00:00
|
|
|
}
|
|
|
|
|
2023-04-25 09:37:42 +00:00
|
|
|
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")
|
|
|
|
}
|
|
|
|
}
|