package main import ( "git.metznet.ca/MetzNet/htmxmqtt" "errors" "os/signal" "syscall" ) func main() { handler_client, err := NewMQTTHandlerClient("tcp://localhost:1883", "", "", "htmx") if err != nil { panic(err) } handler_1, err := handler_client.NewHandler("test", PayloadFormatFunc(`
%s
`)) if err != nil { panic(err) } mux := http.NewServeMux() mux.Handle("/", http.FileServer(http.Dir("./site"))) mux.Handle("/ws", handler_1) server := &http.Server{ Handler: mux, Addr: ":8080", } sigs := make(chan os.Signal, 1) signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM, syscall.SIGTERM, syscall.SIGKILL) go func(sigs chan os.Signal, server *http.Server) { <- sigs server.Close() }(sigs, server) err = server.ListenAndServe() if errors.Is(err, http.ErrServerClosed) == true { os.Stderr.WriteString("Server closed on signal\n") } else if err != nil { os.Stderr.WriteString(fmt.Sprintf("Server error: %s\n", err)) } else { os.Stderr.WriteString("Server closed\n") } }