personal-website/main.go

101 lines
2.6 KiB
Go
Raw Normal View History

2023-03-15 00:05:24 +00:00
package main
import (
2023-04-25 09:37:42 +00:00
"context"
"errors"
2023-03-15 00:05:24 +00:00
"log"
2023-04-25 09:37:42 +00:00
"os"
2023-05-02 00:12:43 +00:00
2023-05-03 21:50:08 +00:00
"personalwebsite/apps"
2023-05-18 01:57:44 +00:00
blogwriter "personalwebsite/apps/BlogWriter"
2023-05-24 22:51:37 +00:00
"personalwebsite/apps/aboutme"
2023-05-03 21:50:08 +00:00
"personalwebsite/apps/blogviewer"
"personalwebsite/apps/finder"
imgviewer "personalwebsite/apps/img-viewer"
2023-07-19 01:35:17 +00:00
"personalwebsite/apps/sunboard"
"personalwebsite/routes"
2023-04-29 13:58:39 +00:00
"personalwebsite/wde"
2023-04-25 09:37:42 +00:00
"personalwebsite/webfilesystem"
2023-03-15 00:05:24 +00:00
2023-04-25 09:37:42 +00:00
"github.com/joho/godotenv"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
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())
}
dBName, err := FindEnv("DATABASE")
if err != nil {
panic(err.Error())
}
webFsCollection, err := FindEnv("COLLECTION_WEBFS")
if err != nil {
panic(err.Error())
}
2023-05-23 23:19:21 +00:00
publicPort, err := FindEnv("PUBLIC_PORT")
if err != nil {
panic(err.Error())
}
privatePort, err := FindEnv("PRIVATE_PORT")
if err != nil {
panic(err.Error())
}
2023-04-25 09:37:42 +00:00
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)
2023-03-18 00:34:56 +00:00
2023-05-01 12:32:41 +00:00
webde := wde.NewWDE(webfs)
2023-05-18 01:57:44 +00:00
//TODO Split to different apps init for private and public?
2023-05-24 22:51:37 +00:00
persPropsApp := aboutme.NewAboutMeApp(webfs)
2023-04-29 13:58:39 +00:00
finderApp := finder.NewFinderApplication(webfs)
2023-04-29 16:47:12 +00:00
imgViewerApp := imgviewer.NewImgViewerApp(webfs)
2023-04-29 12:02:25 +00:00
blogViewerApp := blogviewer.NewBlogViewerApp(webfs)
2023-05-18 01:57:44 +00:00
blogWriterApp := blogwriter.NewBlogWriterApp(webfs)
2023-07-19 16:38:28 +00:00
sunBoardApp := sunboard.NewSunboardApp(webfs, appsStorage)
2023-07-22 15:55:23 +00:00
appsStorage.Apps["personal-properties"] = persPropsApp
2023-04-29 13:58:39 +00:00
appsStorage.Apps["finder"] = finderApp
appsStorage.Apps["img-viewer"] = imgViewerApp
2023-05-18 01:57:44 +00:00
appsStorage.Apps[blogViewerApp.GetAppID()] = blogViewerApp
appsStorage.Apps["BlogWriter"] = blogWriterApp
2023-07-19 01:35:17 +00:00
appsStorage.Apps["Sunboard"] = sunBoardApp
2023-05-01 12:32:41 +00:00
2023-05-23 23:19:21 +00:00
go routes.PublicRoutes(publicPort, webfs, webde, appsStorage)
routes.PrivateRoutes(privatePort, webfs, webde, appsStorage)
2023-03-15 00:05:24 +00:00
}
2023-07-22 15:56:51 +00:00
// TODO to for loop with aal vars in slice
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")
}
}