Skip to content

Commit 7435ffd

Browse files
Add check api url
This url is so you can check a repository is receiving events.
1 parent d009665 commit 7435ffd

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

internal/app/net/http.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ func NewHttpServer(config *app.Config, db *gorm.DB) *Http {
8282
w.Write([]byte("ok"))
8383
})
8484

85+
s.router.Get("/api/check/{repoId}", s.check)
86+
8587
s.router.Post("/api/metric", s.createMetric)
8688

8789
// Protected routes
@@ -126,6 +128,21 @@ type MetricRequest struct {
126128
Pid string `json:"p"`
127129
}
128130

131+
func (s *Http) check(w http.ResponseWriter, r *http.Request) {
132+
repoId := chi.URLParam(r, "repoId")
133+
134+
// Get last event for repoId
135+
result, hasResult := s.statsService.LastEvent(repoId)
136+
137+
if !hasResult {
138+
http.Error(w, "No events found", http.StatusNotFound)
139+
return
140+
}
141+
142+
// Return timestamp from last event in iso8601 format
143+
w.Write([]byte(result.Timestamp.Format("2006-01-02T15:04:05Z")))
144+
}
145+
129146
func (s *Http) createMetric(w http.ResponseWriter, r *http.Request) {
130147
// Metric request is different to a eventRequest as only some data comes
131148
// from the json body

0 commit comments

Comments
 (0)