dorfylegends/backend/main.go

50 lines
880 B
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-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
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-04-26 18:39:24 +03:00
d := flag.Bool("d", false, "debug templates")
2022-04-13 15:01:20 +03:00
flag.Parse()
2022-04-26 18:39:24 +03:00
templates.DebugTemplates = *d
2022-04-13 15:01:20 +03:00
if len(*f) > 0 {
2022-04-20 13:46:42 +03:00
if *p {
defer profile.Start(profile.ProfilePath(".")).Stop()
go func() {
http.ListenAndServe(":8081", nil)
}()
}
2022-04-14 16:49:09 +03:00
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 {
fmt.Println(err)
2022-04-14 16:49:09 +03:00
os.Exit(1)
2022-04-13 15:01:20 +03:00
}
2022-04-14 16:49:09 +03:00
runtime.GC()
2022-04-26 10:24:16 +03:00
server.StartServer(w, static)
2022-04-09 19:37:44 +03:00
2022-04-26 18:39:24 +03:00
} else {
server.StartServer(nil, static)
}
2022-04-09 12:01:04 +03:00
}