Skip to content

Commit

Permalink
support plain text message api
Browse files Browse the repository at this point in the history
  • Loading branch information
metachris committed Oct 23, 2024
1 parent 46ab80f commit 346dabf
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions cmd/system-api/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,21 @@ func (s *Server) handleGetEvents(w http.ResponseWriter, r *http.Request) {
s.eventsLock.RLock()
defer s.eventsLock.RUnlock()

// respond either as JSON or plain text
if r.URL.Query().Get("format") == "text" {
// write events as plain text response
w.Header().Set("Content-Type", "text/plain")
for _, event := range s.events {
_, err := w.Write([]byte(event.ReceivedAt.Format("2006-01-02 15:04:05 UTC") + " \t " + event.Message + "\n"))
if err != nil {
s.log.Error("Failed to write event", "err", err)
w.WriteHeader(http.StatusInternalServerError)
return
}
}
return
}

// write events as JSON response
w.Header().Set("Content-Type", "application/json")
err := json.NewEncoder(w).Encode(s.events)
Expand Down

0 comments on commit 346dabf

Please sign in to comment.