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.
|
|
|
|
package main
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
"flag"
|
|
|
|
|
"io"
|
|
|
|
|
"log/slog"
|
|
|
|
|
"os"
|
|
|
|
|
"os/signal"
|
|
|
|
|
"syscall"
|
|
|
|
|
"time"
|
|
|
|
|
|
|
|
|
|
"code.ndumas.com/ndumas/muddy/core"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
appConfig := core.AppConfig{
|
|
|
|
|
Port: ":3001",
|
|
|
|
|
|
|
|
|
|
LogDest: io.MultiWriter(f, os.Stderr),
|
|
|
|
|
LogLevel: level,
|
|
|
|
|
|
|
|
|
|
TickInterval: time.Millisecond * 30,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
app := core.New(appConfig)
|
|
|
|
|
|
|
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
|
|
|
|
|
|
c := make(chan os.Signal, 1)
|
|
|
|
|
signal.Notify(c, os.Interrupt, syscall.SIGTERM)
|
|
|
|
|
go func() {
|
|
|
|
|
<-c
|
|
|
|
|
app.L.Info("shutting down")
|
|
|
|
|
cancel()
|
|
|
|
|
}()
|
|
|
|
|
|
|
|
|
|
app.Run(ctx)
|
|
|
|
|
}
|