middleware_metric_handler.go 745 B

12345678910111213141516171819202122232425262728293031323334
  1. package got
  2. import (
  3. G "github.com/dave/jennifer/jen"
  4. )
  5. var (
  6. parser = "github.com/eugeniucarvalho/metric-query-parser/parser"
  7. GenMetricsStmts = &Middleware{
  8. Id: "metrics",
  9. Type: "method",
  10. Fn: func(ctx *MiddlewareContext) error {
  11. ctx.Statement.Block(G.Id(`
  12. var (
  13. metrics = `).Qual(parser, "MetricsMap").Values().Id(`
  14. errResolve error
  15. )
  16. if err = api.ReadJson(ctx, &metrics); err != nil {
  17. return
  18. }
  19. if resp, errResolve = `).Qual(parser, "NewMetricQueryParser").Call().Id(`.Resolve(metrics); errResolve != nil {
  20. err = errs.Internal().Details(&errs.Detail{
  21. Reason: "metricHandlerError",
  22. Message: errResolve.Error(),
  23. })
  24. }
  25. return`)).Line()
  26. return nil
  27. },
  28. }
  29. )