dorfylegends/main.go

88 lines
3.0 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"
2022-04-13 08:28:07 +03:00
"legendsbrowser/analyze"
2022-04-09 19:37:44 +03:00
"legendsbrowser/model"
"legendsbrowser/server"
2022-04-09 12:01:04 +03:00
"net/http"
2022-04-11 00:27:37 +03:00
_ "net/http/pprof"
2022-04-13 08:28:07 +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-09 12:01:04 +03:00
)
2022-04-09 19:37:44 +03:00
var world model.World
2022-04-09 12:01:04 +03:00
func main() {
2022-04-13 08:28:07 +03:00
var a string
flag.StringVar(&a, "a", "", "analyze a file")
flag.Parse()
if len(a) == 0 {
fmt.Println("Usage: defaults.go -a")
flag.PrintDefaults()
os.Exit(1)
} else {
analyze.Analyze(a)
os.Exit(1)
}
defer profile.Start(profile.MemProfile).Stop()
go func() {
http.ListenAndServe(":8081", nil)
}()
2022-04-11 00:27:37 +03:00
2022-04-09 12:01:04 +03:00
fmt.Println("Hallo Welt!")
2022-04-11 23:30:43 +03:00
// world.Load("region1-00152-01-01-legends_plus.xml")
2022-04-11 00:27:37 +03:00
world.Load("region2-00195-01-01-legends.xml")
2022-04-11 23:30:43 +03:00
// world.Load("Agora-00033-01-01-legends_plus.xml")
2022-04-11 00:27:37 +03:00
runtime.GC()
2022-04-09 19:37:44 +03:00
world.Process()
2022-04-09 12:01:04 +03:00
2022-04-11 23:30:43 +03:00
// 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)
2022-04-09 12:01:04 +03:00
router := mux.NewRouter().StrictSlash(true)
2022-04-09 19:37:44 +03:00
server.RegisterResource(router, "region", world.RegionMap)
server.RegisterResource(router, "undergroundRegion", world.UndergroundRegionMap)
server.RegisterResource(router, "landmass", world.LandmassMap)
server.RegisterResource(router, "site", world.SiteMap)
server.RegisterResource(router, "worldConstruction", world.WorldConstructionMap)
server.RegisterResource(router, "artifact", world.ArtifactMap)
server.RegisterResource(router, "hf", world.HistoricalFigureMap)
server.RegisterResource(router, "collection", world.HistoricalEventCollectionMap)
server.RegisterResource(router, "entity", world.EntityMap)
server.RegisterResource(router, "event", world.HistoricalEventMap)
2022-04-11 23:30:43 +03:00
server.RegisterResource(router, "era", world.HistoricalEraMap)
server.RegisterResource(router, "danceForm", world.DanceFormMap)
server.RegisterResource(router, "musicalForm", world.MusicalFormMap)
server.RegisterResource(router, "poeticForm", world.PoeticFormMap)
server.RegisterResource(router, "written", world.WrittenContentMap)
2022-04-09 19:37:44 +03:00
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 12:01:04 +03:00
}