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.

70 lines
1.4 KiB
Go

4 years ago
package main
import (
"os"
"os/signal"
"time"
"github.com/jordanorelli/astro-domu/internal/app"
"github.com/jordanorelli/astro-domu/internal/exit"
"github.com/jordanorelli/astro-domu/internal/sim"
"github.com/jordanorelli/blammo"
4 years ago
)
func newLog(path string) *blammo.Log {
4 years ago
f, err := os.OpenFile("./astro.log", os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0644)
if err != nil {
exit.WithMessage(1, "unable to open log file %q for writing: %v", err)
}
w := blammo.NewLineWriter(f)
options := []blammo.Option{
blammo.DebugWriter(w),
blammo.InfoWriter(w),
blammo.ErrorWriter(w),
}
4 years ago
return blammo.NewLog("astro", options...)
}
4 years ago
func main() {
4 years ago
if len(os.Args) < 2 {
exit.WithMessage(1, "client or server?")
}
switch os.Args[1] {
case "client":
runClient()
4 years ago
case "server":
s := sim.Server{}
4 years ago
if err := s.Start("cdm.jordanorelli.com", 12805); err != nil {
exit.WithMessage(1, "unable to start server: %v", err)
4 years ago
}
sig := make(chan os.Signal, 1)
signal.Notify(sig, os.Interrupt)
<-sig
4 years ago
s.Shutdown()
4 years ago
default:
exit.WithMessage(1, "supported options are [client|server]")
}
}
func runClient() {
4 years ago
log := newLog("./astro.log").Child("client")
start := time.Now()
log.Info("starting at: %v", start)
defer func() {
finished := time.Now()
log.Info("finished at: %v", finished)
log.Info("total play time: %v", finished.Sub(start))
}()
app := app.UI{
Log: log.Child("ui"),
}
app.Run()
4 years ago
}