package main import ( "context" "errors" "log" "os" "personalwebsite/apps" blogwriter "personalwebsite/apps/BlogWriter" "personalwebsite/apps/aboutme" "personalwebsite/apps/blogviewer" "personalwebsite/apps/finder" imgviewer "personalwebsite/apps/img-viewer" "personalwebsite/apps/sunboard" "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 := aboutme.NewAboutMeApp(webfs) finderApp := finder.NewFinderApplication(webfs) imgViewerApp := imgviewer.NewImgViewerApp(webfs) blogViewerApp := blogviewer.NewBlogViewerApp(webfs) blogWriterApp := blogwriter.NewBlogWriterApp(webfs) sunBoardApp := sunboard.NewSunboardApp(webfs, appsStorage) appsStorage.Apps["personal-properties"] = persPropsApp appsStorage.Apps["finder"] = finderApp appsStorage.Apps["img-viewer"] = imgViewerApp appsStorage.Apps[blogViewerApp.GetAppID()] = blogViewerApp appsStorage.Apps["BlogWriter"] = blogWriterApp appsStorage.Apps["Sunboard"] = sunBoardApp 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") } }