personal-website/main.go

92 lines
2.2 KiB
Go

package main
import (
"context"
"errors"
"os"
"personalwebsite/webfs"
"github.com/joho/godotenv"
"personalwebsite/routes"
)
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 := 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)
if err != nil {
panic(err.Error())
}
routes.ApiRoutes()
}
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")
}
}