handleStats returns count and last_received_at for SMTP messages.
(store event.Store)
| 168 | |
| 169 | // handleStats returns count and last_received_at for SMTP messages. |
| 170 | func 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. |
| 194 | func handleRaw(store event.Store) http.HandlerFunc { |
no test coverage detected