From a4ecc652e3e44d7477820f545eba4ccfa1096593 Mon Sep 17 00:00:00 2001 From: Caleb Denio Date: Mon, 25 Apr 2022 12:18:58 -0400 Subject: [PATCH] add api --- pkg/jia/server.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/pkg/jia/server.go b/pkg/jia/server.go index 390bf8a..9cde8b6 100644 --- a/pkg/jia/server.go +++ b/pkg/jia/server.go @@ -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) }