You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

58 lines
989 B
Go

package main
import (
"context"
"flag"
"log/slog"
"os"
"os/signal"
"syscall"
"code.ndumas.com/ndumas/muddy/core"
"code.ndumas.com/ndumas/muddy/systems"
)
func main() {
var (
level string
logFile string
)
flag.StringVar(&level, "level", "INFO", "Log level: INFO/info, DEBUG/debug, or ERROR/error.")
flag.StringVar(&logFile, "log", "out.log", "Path to log file.")
flag.Parse()
f, err := os.Create(logFile)
if err != nil {
slog.With(
slog.Any("error", err),
).Error("could not open log file")
os.Exit(1)
}
app := core.New(level, f)
rs := &systems.RoomSystem{
Rooms: make(map[uint64]*systems.Room, 0),
L: app.L.With(slog.String("system", "room")),
}
app.W.AddSystem(rs)
app.L.With(
slog.Int("room count", len(rs.Rooms)),
).Info("setup complete")
ctx, cancel := context.WithCancel(context.Background())
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt, syscall.SIGTERM)
go func() {
<-c
cancel()
}()
app.Run(ctx)
}