This commit is contained in:
@@ -2,7 +2,9 @@ package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"os/signal"
|
||||
"strings"
|
||||
@@ -31,6 +33,23 @@ func main() {
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
if conf.Debug.Enabled {
|
||||
mux := http.NewServeMux()
|
||||
|
||||
mux.HandleFunc("/state", func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
w.WriteHeader(200)
|
||||
_ = json.NewEncoder(w).Encode(bot.ClientState())
|
||||
})
|
||||
|
||||
go func() {
|
||||
err := http.ListenAndServe(conf.Debug.Listen, mux)
|
||||
if err != nil {
|
||||
log.Println("Failed to setup debug listener", err)
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
// Listen for a quit signal.
|
||||
interrupt := make(chan os.Signal, 1)
|
||||
signal.Notify(interrupt, os.Interrupt)
|
||||
|
||||
Reference in New Issue
Block a user