dorfylegends/backend/main.go
Robert Janetzko 9f38f9b17d map
2022-05-01 10:29:39 +00:00

52 lines
900 B
Go

package main
import (
"embed"
"flag"
"log"
"net/http"
_ "net/http/pprof"
"runtime"
"github.com/pkg/profile"
"github.com/robertjanetzko/LegendsBrowser2/backend/model"
"github.com/robertjanetzko/LegendsBrowser2/backend/server"
"github.com/robertjanetzko/LegendsBrowser2/backend/templates"
)
//go:embed static
var static embed.FS
func main() {
f := flag.String("f", "", "open a file")
p := flag.Bool("p", false, "start profiling")
d := flag.Bool("d", false, "debug templates")
flag.Parse()
templates.DebugTemplates = *d
var world *model.DfWorld
if len(*f) > 0 {
if *p {
defer profile.Start(profile.ProfilePath(".")).Stop()
go func() {
http.ListenAndServe(":8081", nil)
}()
}
w, err := model.Parse(*f, nil)
if err != nil {
log.Fatal(err)
}
runtime.GC()
world = w
}
err := server.StartServer(world, static)
if err != nil {
log.Fatal(err)
}
}