package main import ( "context" "log" "net" "net/http" "os" "os/signal" "strconv" "time" "forge.lightcrystal.systems/lightcrystal/underbbs/server" ) func main() { err := run() if err != nil { log.Fatal(err) } } func run() error { l, err := net.Listen("tcp", ":"+strconv.FormatInt(int64(9090), 10)) if err != nil { return err } bbsServer := server.New() s := &http.Server{ Handler: bbsServer, ReadTimeout: time.Second * 10, WriteTimeout: time.Second * 10, } errc := make(chan error, 1) go func() { errc <- s.Serve(l) }() sigs := make(chan os.Signal, 1) signal.Notify(sigs, os.Interrupt) select { case err := <-errc: log.Printf("failed to serve: %v", err) case sig := <-sigs: log.Printf("terminating: %v", sig) } ctx, cancel := context.WithTimeout(context.Background(), time.Second*10) defer cancel() return s.Shutdown(ctx) }