dorfylegends/backend/main.go

63 lines
1.1 KiB
Go
Raw Normal View History

2022-04-09 12:01:04 +03:00
package main
import (
2022-04-15 17:46:51 +03:00
"embed"
2022-04-13 08:28:07 +03:00
"flag"
2022-05-07 18:08:42 +03:00
"fmt"
2022-05-01 13:29:39 +03:00
"log"
2022-04-09 12:01:04 +03:00
"net/http"
2022-04-11 00:27:37 +03:00
_ "net/http/pprof"
"runtime"
2022-04-09 12:01:04 +03:00
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"
2022-04-26 10:24:16 +03:00
"github.com/robertjanetzko/LegendsBrowser2/backend/server"
2022-04-26 18:39:24 +03:00
"github.com/robertjanetzko/LegendsBrowser2/backend/templates"
2022-04-09 12:01:04 +03:00
)
2022-04-19 12:46:43 +03:00
//go:embed static
var static embed.FS
2022-04-15 17:46:51 +03:00
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")
2022-04-20 13:46:42 +03:00
p := flag.Bool("p", false, "start profiling")
2022-05-05 13:55:33 +03:00
c := flag.String("c", "", "config file")
l := flag.Bool("l", false, "open last file")
2022-04-13 15:01:20 +03:00
flag.Parse()
2022-05-03 22:39:00 +03:00
if *p {
defer profile.Start(profile.ProfilePath(".")).Stop()
go func() {
http.ListenAndServe(":8081", nil)
}()
}
2022-05-05 13:55:33 +03:00
config, err := server.LoadConfig(*c)
if err != nil {
log.Fatal(err)
}
templates.DebugTemplates = config.DebugTemplates
2022-04-26 18:39:24 +03:00
2022-05-01 13:29:39 +03:00
var world *model.DfWorld
2022-05-05 13:55:33 +03:00
if *l {
*f = config.LastFile
}
2022-04-13 15:01:20 +03:00
if len(*f) > 0 {
2022-04-26 22:00:09 +03:00
w, err := model.Parse(*f, nil)
2022-04-13 15:01:20 +03:00
if err != nil {
2022-05-07 18:08:42 +03:00
fmt.Println(err)
} else {
runtime.GC()
world = w
2022-04-13 15:01:20 +03:00
}
2022-05-01 13:29:39 +03:00
}
2022-04-09 19:37:44 +03:00
2022-05-05 13:55:33 +03:00
err = server.StartServer(config, world, static)
2022-05-01 13:29:39 +03:00
if err != nil {
log.Fatal(err)
2022-04-26 18:39:24 +03:00
}
2022-04-09 12:01:04 +03:00
}