MCPcopy Create free account
hub / github.com/buggregator/server / handleStats

Function handleStats

modules/smtp/api.go:170–191  ·  view source on GitHub ↗

handleStats returns count and last_received_at for SMTP messages.

(store event.Store)

Source from the content-addressed store, hash-verified

168
169// handleStats returns count and last_received_at for SMTP messages.
170func handleStats(store event.Store) http.HandlerFunc {
171 return func(w http.ResponseWriter, r *http.Request) {
172 project := r.URL.Query().Get("project")
173 events, err := store.FindAll(r.Context(), event.FindOptions{Type: "smtp", Project: project})
174 if err != nil {
175 smtpError(w, err.Error(), http.StatusInternalServerError)
176 return
177 }
178
179 var lastReceivedAt *string
180 if len(events) > 0 {
181 // Events are ordered desc by timestamp; the first is the most recent.
182 t := time.Unix(0, int64(events[0].Timestamp*1e9)).UTC().Format(time.RFC3339)
183 lastReceivedAt = &t
184 }
185
186 smtpJSON(w, map[string]any{
187 "count": len(events),
188 "last_received_at": lastReceivedAt,
189 })
190 }
191}
192
193// handleRaw returns the original RFC 822 source of an SMTP message.
194func handleRaw(store event.Store) http.HandlerFunc {

Callers 1

registerSMTPAPIFunction · 0.85

Calls 4

smtpErrorFunction · 0.85
smtpJSONFunction · 0.85
FindAllMethod · 0.65
GetMethod · 0.45

Tested by

no test coverage detected