feat(api): Add optional duration to external endpoint results (#1092)

* feat(api): Add optional duration to external endpoint results

* Fix failing tests

* Parse duration regardless of success

* Use len instead of equality

* Update README.md

* Include error in output

* Fix result numbering

* Update README.md

* Update api/external_endpoint.go

---------

Co-authored-by: TwiN <twin@linux.com>
This commit is contained in:
Bryan Cross
2025-07-08 10:53:57 -05:00
committed by GitHub
parent 1855718e46
commit 9b1d15c9e0
3 changed files with 33 additions and 9 deletions

View File

@@ -46,6 +46,14 @@ func CreateExternalEndpointResult(cfg *config.Config) fiber.Handler {
Success: c.QueryBool("success"),
Errors: []string{},
}
if len(c.Query("duration")) > 0 {
parsedDuration, err := time.ParseDuration(c.Query("duration"))
if err != nil {
logr.Errorf("[api.CreateExternalEndpointResult] Invalid duration from string=%s with error: %s", c.Query("duration"), err.Error())
return c.Status(400).SendString("invalid duration: " + err.Error())
}
result.Duration = parsedDuration
}
if !result.Success && c.Query("error") != "" {
result.Errors = append(result.Errors, c.Query("error"))
}