dorfylegends/backend/main.go

84 lines
2.9 KiB
Go
Raw Normal View History

2022-04-09 12:01:04 +03:00
package main
import (
2022-04-13 08:28:07 +03:00
"flag"
2022-04-09 12:01:04 +03:00
"fmt"
"net/http"
2022-04-11 00:27:37 +03:00
_ "net/http/pprof"
2022-04-14 16:49:09 +03:00
"os"
2022-04-11 00:27:37 +03:00
"runtime"
2022-04-09 12:01:04 +03:00
"github.com/gorilla/mux"
2022-04-13 08:28:07 +03:00
"github.com/pkg/profile"
2022-04-14 18:39:18 +03:00
"github.com/robertjanetzko/LegendsBrowser2/backend/model"
"github.com/robertjanetzko/LegendsBrowser2/backend/server"
2022-04-09 12:01:04 +03:00
)
2022-04-14 18:39:18 +03:00
var world *model.DfWorld
2022-04-09 12:01:04 +03:00
func main() {
2022-04-13 15:01:20 +03:00
f := flag.String("f", "", "open a file")
flag.Parse()
if len(*f) > 0 {
2022-04-14 16:49:09 +03:00
defer profile.Start(profile.MemProfile).Stop()
go func() {
http.ListenAndServe(":8081", nil)
}()
2022-04-14 18:39:18 +03:00
w, err := model.Parse(*f)
2022-04-13 15:01:20 +03:00
if err != nil {
fmt.Println(err)
2022-04-14 16:49:09 +03:00
os.Exit(1)
2022-04-13 15:01:20 +03:00
}
world = w
2022-04-09 12:01:04 +03:00
2022-04-14 16:49:09 +03:00
fmt.Println("Hallo Welt!")
runtime.GC()
// world.Process()
// model.ListOtherElements("world", &[]*model.World{&world})
// model.ListOtherElements("region", &world.Regions)
// model.ListOtherElements("underground regions", &world.UndergroundRegions)
// model.ListOtherElements("landmasses", &world.Landmasses)
// model.ListOtherElements("sites", &world.Sites)
// model.ListOtherElements("world constructions", &world.WorldConstructions)
// model.ListOtherElements("artifacts", &world.Artifacts)
// model.ListOtherElements("entities", &world.Entities)
// model.ListOtherElements("hf", &world.HistoricalFigures)
// model.ListOtherElements("events", &world.HistoricalEvents)
// model.ListOtherElements("collections", &world.HistoricalEventCollections)
// model.ListOtherElements("era", &world.HistoricalEras)
// model.ListOtherElements("danceForm", &world.DanceForms)
// model.ListOtherElements("musicalForm", &world.MusicalForms)
// model.ListOtherElements("poeticForm", &world.PoeticForms)
// model.ListOtherElements("written", &world.WrittenContents)
router := mux.NewRouter().StrictSlash(true)
server.RegisterResource(router, "region", world.Regions)
// server.RegisterResource(router, "undergroundRegion", world.UndergroundRegions)
server.RegisterResource(router, "landmass", world.Landmasses)
server.RegisterResource(router, "site", world.Sites)
server.RegisterResource(router, "worldConstruction", world.WorldConstructions)
server.RegisterResource(router, "artifact", world.Artifacts)
server.RegisterResource(router, "hf", world.HistoricalFigures)
server.RegisterResource(router, "collection", world.HistoricalEventCollections)
server.RegisterResource(router, "entity", world.Entities)
server.RegisterResource(router, "event", world.HistoricalEvents)
// server.RegisterResource(router, "era", world.HistoricalEras)
server.RegisterResource(router, "danceForm", world.DanceForms)
server.RegisterResource(router, "musicalForm", world.MusicalForms)
server.RegisterResource(router, "poeticForm", world.PoeticForms)
// server.RegisterResource(router, "written", world.WrittenContents)
spa := server.SpaHandler{StaticPath: "frontend/dist/legendsbrowser", IndexPath: "index.html"}
router.PathPrefix("/").Handler(spa)
fmt.Println("Serving at :8080")
http.ListenAndServe(":8080", router)
}
2022-04-09 19:37:44 +03:00
2022-04-09 12:01:04 +03:00
}