This commit is contained in:
Caleb Denio 2022-04-25 12:18:58 -04:00
parent 160f826212
commit a4ecc652e3
No known key found for this signature in database
GPG key ID: D2E75BDDE8F717AD

View file

@ -37,6 +37,23 @@ func StartServer(config *Config) {
http.HandleFunc("/slack/events", handleSlackEvents)
http.HandleFunc("/slack/leaderboard", HandleLeaderboardSlashCommand)
http.HandleFunc("/slack/eventsCommand", HandleEventsSlashCommand)
http.HandleFunc("/api/currentNumber", func(w http.ResponseWriter, r *http.Request) {
number, err := redisClient.Get("last_valid_number").Int()
if err != nil {
w.WriteHeader(500)
w.Write([]byte(err.Error()))
return
}
response, _ := json.Marshal(struct {
CurrentNumber int `json:"number"`
}{
CurrentNumber: number,
})
w.Header().Add("Content-Type", "application/json")
w.Write(response)
})
http.ListenAndServe(fmt.Sprintf("0.0.0.0:%d", config.Port), nil)
}