package routes import ( "fmt" "log" "github.com/gofiber/fiber/v2" ) func (r *Router) ApiMonitor(api fiber.Router) { // Respond to requests like // - "/api/monitor/status?script=SCRIPT_NAME" where SCRIPT_NAME is the name of a file inside "./scripts" api.Get("/status", func(c *fiber.Ctx) error { if qScript := c.Query("script"); qScript != "" { log.Printf("Script %q", qScript) output, err := r.Monitor.GetLastOutput(qScript) if err != nil { return err } return c.JSON(output) } return fmt.Errorf("no script, device or entity provided") }) }