Skip to content

Commit

Permalink
☔ Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
wesen committed May 8, 2024
1 parent 9adb10b commit bd7874e
Show file tree
Hide file tree
Showing 27 changed files with 375 additions and 355 deletions.
2 changes: 1 addition & 1 deletion cmd/parka/cmds/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ var ServeCmd = &cobra.Command{
Str("templateDir", "pkg/web/src/templates").
Msg("Using assets from disk")
serverOptions = append(serverOptions,
server.WithStaticPaths(fs.NewStaticPath(http.FS(os.DirFS("pkg/web/dist")), "/dist")),
server.WithStaticPaths(fs.NewStaticPath(os.DirFS("pkg/web/dist"), "/dist")),
)
defaultLookups = append(defaultLookups, render.NewLookupTemplateFromDirectory("pkg/web/src/templates"))
} else {
Expand Down
12 changes: 8 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,13 @@ require (
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/cpuid/v2 v2.2.4 // indirect
github.com/kopoli/go-terminal-size v0.0.0-20170219200355-5c97524c8b54 // indirect
github.com/labstack/echo/v4 v4.12.0 // indirect
github.com/labstack/gommon v0.4.2 // indirect
github.com/leodido/go-urn v1.2.4 // indirect
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mattn/go-colorable v0.1.12 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mattn/go-runewidth v0.0.15 // indirect
github.com/microcosm-cc/bluemonday v1.0.25 // indirect
Expand All @@ -105,17 +107,19 @@ require (
github.com/tj/go-naturaldate v1.3.0 // indirect
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
github.com/ugorji/go/codec v1.2.11 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/fasttemplate v1.2.2 // indirect
github.com/wk8/go-ordered-map/v2 v2.1.8 // indirect
github.com/xuri/efp v0.0.0-20220603152613-6918739fd470 // indirect
github.com/xuri/excelize/v2 v2.7.1 // indirect
github.com/xuri/nfp v0.0.0-20220409054826-5e722a1d9e22 // indirect
github.com/yuin/goldmark-emoji v1.0.2 // indirect
go.mongodb.org/mongo-driver v1.11.3 // indirect
golang.org/x/arch v0.3.0 // indirect
golang.org/x/crypto v0.16.0 // indirect
golang.org/x/crypto v0.22.0 // indirect
golang.org/x/image v0.14.0 // indirect
golang.org/x/net v0.19.0 // indirect
golang.org/x/sys v0.18.0 // indirect
golang.org/x/net v0.24.0 // indirect
golang.org/x/sys v0.19.0 // indirect
golang.org/x/text v0.14.0 // indirect
google.golang.org/protobuf v1.31.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
Expand Down
18 changes: 18 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,10 @@ github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/labstack/echo/v4 v4.12.0 h1:IKpw49IMryVB2p1a4dzwlhP1O2Tf2E0Ir/450lH+kI0=
github.com/labstack/echo/v4 v4.12.0/go.mod h1:UP9Cr2DJXbOK3Kr9ONYzNowSh7HP0aG0ShAyycHSJvM=
github.com/labstack/gommon v0.4.2 h1:F8qTUNXgG1+6WQmqoUWnz8WiEU60mXVVw0P4ht1WRA0=
github.com/labstack/gommon v0.4.2/go.mod h1:QlUFxVM+SNXhDL/Z7YhocGIBYOiwB0mXm1+1bAPHPyU=
github.com/leodido/go-urn v1.2.4 h1:XlAE/cm/ms7TE/VMVoduSpNBoyc2dOxHs5MZSwAN63Q=
github.com/leodido/go-urn v1.2.4/go.mod h1:7ZrI8mTSeBSHl/UaRyKQW1qZeMgak41ANeCNaVckg+4=
github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY=
Expand All @@ -276,7 +280,10 @@ github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0
github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
github.com/mattn/go-colorable v0.1.12 h1:jF+Du6AlPIjs2BiUiQlKOX0rt3SujHxPnksPKZbaA40=
github.com/mattn/go-colorable v0.1.12/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4=
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
Expand Down Expand Up @@ -373,6 +380,10 @@ github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS
github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08=
github.com/ugorji/go/codec v1.2.11 h1:BMaWp1Bb6fHwEtbplGBGJ498wD+LKlNSl25MjdZY4dU=
github.com/ugorji/go/codec v1.2.11/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg=
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
github.com/valyala/fasttemplate v1.2.2 h1:lxLXG0uE3Qnshl9QyaK6XJxMXlQZELvChBOCmQD0Loo=
github.com/valyala/fasttemplate v1.2.2/go.mod h1:KHLXt3tVN2HBp8eijSv/kGJopbvo7S+qRAEEKiv+SiQ=
github.com/wk8/go-ordered-map/v2 v2.1.8 h1:5h/BUHu93oj4gIdvHHHGsScSTMijfx5PeYkE/fJgbpc=
github.com/wk8/go-ordered-map/v2 v2.1.8/go.mod h1:5nJHM5DyteebpVlHnWMV0rPz6Zp7+xBAnxjb1X5vnTw=
github.com/xdg-go/pbkdf2 v1.0.0/go.mod h1:jrpuAogTd400dnrH08LKmI/xc1MbPOebTwRqcT5RDeI=
Expand Down Expand Up @@ -422,6 +433,8 @@ golang.org/x/crypto v0.0.0-20220722155217-630584e8d5aa/go.mod h1:IxCIyHEi3zRg3s0
golang.org/x/crypto v0.8.0/go.mod h1:mRqEX+O9/h5TFCrQhkgjo2yKi0yYA+9ecGkdQoHrywE=
golang.org/x/crypto v0.16.0 h1:mMMrFzRSCF0GvB7Ne27XVtVAaXLrPmgPC7/v0tkwHaY=
golang.org/x/crypto v0.16.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4=
golang.org/x/crypto v0.22.0 h1:g1v0xeRhjcugydODzvb3mEM9SQ0HGp9s/nh3COQ/C30=
golang.org/x/crypto v0.22.0/go.mod h1:vr6Su+7cTlO45qkww3VDJlzDn0ctJvRgYbC2NvXHt+M=
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8=
Expand Down Expand Up @@ -497,6 +510,8 @@ golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
golang.org/x/net v0.9.0/go.mod h1:d48xBJpPfHeWQsugry2m+kC02ZBRGRgulfHnEXEuWns=
golang.org/x/net v0.19.0 h1:zTwKpTd2XuCqf8huc7Fo2iSy+4RHPd10s4KzeTnVr1c=
golang.org/x/net v0.19.0/go.mod h1:CfAk/cbD4CthTvqiEl8NpboMuiuOYsAr/7NOjZJtv1U=
golang.org/x/net v0.24.0 h1:1PcaxkF854Fu3+lvBIx5SYn9wRlBzzcnHZSiaFFAb0w=
golang.org/x/net v0.24.0/go.mod h1:2Q7sJY5mzlzWjKtYUEXSlBWCdyaioyXzRB2RtU8KVE8=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
Expand Down Expand Up @@ -561,12 +576,15 @@ golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220704084225-05e143d24a9e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.7.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4=
golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.19.0 h1:q5f1RH2jigJ1MoAWp2KTp3gm5zAGFUTarQZ5U386+4o=
golang.org/x/sys v0.19.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
Expand Down
4 changes: 2 additions & 2 deletions pkg/NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ and call Run on the underlying glaze.Command.
#### CommandHandlerFunc - parsing incoming requests into a command's parameters and layers

This is done through the `CommandHandlerFunc` type, which is a function that
takes a `*gin.Context` and a `*CommandContext` and is allowed to modify both as
takes a `echo.Context` and a `*CommandContext` and is allowed to modify both as
it does its thing.

A `CommandContext` is a struct that has a reference to the `GlazeCommand` and keeps
Expand All @@ -53,7 +53,7 @@ necessary to run the glaze command.
#### CreateProcessorFunc - creating the output formatter

We also have something called a `CreateProcessorFunc`, which is a function that
takes a `*gin.Context` and a `*CommandContext` and returns a `glaze.Processor`.
takes a `echo.Context` and a `*CommandContext` and returns a `glaze.Processor`.
This allows us to override what output formatter is created, depending on the request.
The default handler will process the parsed parameters for the `glazed` layer, just
as it would on the command line. If nothing is set, it would create a JSON output formatter.
Expand Down
20 changes: 11 additions & 9 deletions pkg/glazed/handlers/datatables/datatables.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"embed"
"fmt"
"github.com/gin-gonic/gin"
"github.com/go-go-golems/glazed/pkg/cmds"
"github.com/go-go-golems/glazed/pkg/cmds/layers"
"github.com/go-go-golems/glazed/pkg/cmds/middlewares"
Expand All @@ -19,6 +18,7 @@ import (
parka_middlewares "github.com/go-go-golems/parka/pkg/glazed/middlewares"
"github.com/go-go-golems/parka/pkg/render"
"github.com/go-go-golems/parka/pkg/render/layout"
"github.com/labstack/echo/v4"
"github.com/pkg/errors"
"github.com/rs/zerolog/log"
"golang.org/x/sync/errgroup"
Expand Down Expand Up @@ -167,7 +167,7 @@ func WithStreamRows(streamRows bool) QueryHandlerOption {

var _ handlers.Handler = &QueryHandler{}

func (qh *QueryHandler) Handle(c *gin.Context, w io.Writer) error {
func (qh *QueryHandler) Handle(c echo.Context) error {
description := qh.cmd.Description()
parsedLayers := layers.NewParsedLayers()

Expand All @@ -181,7 +181,7 @@ func (qh *QueryHandler) Handle(c *gin.Context, w io.Writer) error {

dt_ := qh.dt.Clone()
if cm_, ok := qh.cmd.(cmds.CommandWithMetadata); ok {
dt_.CommandMetadata, err = cm_.Metadata(c, parsedLayers)
dt_.CommandMetadata, err = cm_.Metadata(c.Request().Context(), parsedLayers)
}

var of formatters.RowOutputFormatter
Expand Down Expand Up @@ -217,7 +217,7 @@ func (qh *QueryHandler) Handle(c *gin.Context, w io.Writer) error {
columnsC <- []types.FieldName{}
close(columnsC)
close(rowC)
err_ := qh.renderTemplate(parsedLayers, w, dt_, columnsC)
err_ := qh.renderTemplate(parsedLayers, c.Response(), dt_, columnsC)
if err_ != nil {
return err_
}
Expand All @@ -239,7 +239,7 @@ func (qh *QueryHandler) Handle(c *gin.Context, w io.Writer) error {
gp.AddTableMiddleware(table.NewOutputChannelMiddleware(of, rowC))
}

ctx := c.Request.Context()
ctx := c.Request().Context()
ctx2, cancel := context.WithCancel(ctx)
eg, ctx3 := errgroup.WithContext(ctx2)

Expand Down Expand Up @@ -298,7 +298,7 @@ func (qh *QueryHandler) Handle(c *gin.Context, w io.Writer) error {

eg.Go(func() error {
// if qh.Cmd implements cmds.CommandWithMetadata, get Metadata
err := qh.renderTemplate(parsedLayers, w, dt_, columnsC)
err := qh.renderTemplate(parsedLayers, c.Response(), dt_, columnsC)
if err != nil {
return err
}
Expand Down Expand Up @@ -364,8 +364,8 @@ func CreateDataTablesHandler(
path string,
commandPath string,
options ...QueryHandlerOption,
) gin.HandlerFunc {
return func(c *gin.Context) {
) echo.HandlerFunc {
return func(c echo.Context) error {
name := cmd.Description().Name
dateTime := time.Now().Format("2006-01-02--15-04-05")
links := []layout.Link{
Expand Down Expand Up @@ -415,9 +415,11 @@ func CreateDataTablesHandler(

handler := NewQueryHandler(cmd, options_...)

err := handler.Handle(c, c.Writer)
err := handler.Handle(c)
if err != nil && !errors.Is(err, context.Canceled) {
log.Error().Err(err).Msg("error handling query")
}

return nil
}
}
13 changes: 7 additions & 6 deletions pkg/glazed/handlers/glazed/glazed.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
package glazed

import (
"github.com/gin-gonic/gin"
"github.com/go-go-golems/glazed/pkg/cmds"
"github.com/go-go-golems/glazed/pkg/cmds/layers"
"github.com/go-go-golems/glazed/pkg/cmds/middlewares"
"github.com/go-go-golems/glazed/pkg/cmds/parameters"
"github.com/go-go-golems/glazed/pkg/settings"
"github.com/go-go-golems/parka/pkg/glazed/handlers"
middlewares2 "github.com/go-go-golems/parka/pkg/glazed/middlewares"
"github.com/labstack/echo/v4"
"github.com/pkg/errors"
"io"
"net/http"
)

type QueryHandler struct {
Expand Down Expand Up @@ -40,7 +40,7 @@ func NewQueryHandler(cmd cmds.GlazeCommand, options ...QueryHandlerOption) *Quer

var _ handlers.Handler = (*QueryHandler)(nil)

func (h *QueryHandler) Handle(c *gin.Context, writer io.Writer) error {
func (h *QueryHandler) Handle(c echo.Context) error {
description := h.cmd.Description()
parsedLayers := layers.NewParsedLayers()

Expand All @@ -63,14 +63,15 @@ func (h *QueryHandler) Handle(c *gin.Context, writer io.Writer) error {
return err
}

of, err := settings.SetupProcessorOutput(gp, glazedLayer, writer)
of, err := settings.SetupProcessorOutput(gp, glazedLayer, c.Response())
if err != nil {
return err
}

c.Header("Content-Type", of.ContentType())
c.Response().Header().Set("Content-Type", of.ContentType())
c.Response().WriteHeader(http.StatusOK)

ctx := c.Request.Context()
ctx := c.Request().Context()
err = h.cmd.RunIntoGlazeProcessor(ctx, parsedLayers, gp)
if err != nil {
return err
Expand Down
9 changes: 6 additions & 3 deletions pkg/glazed/handlers/handler.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
package handlers

import (
"github.com/gin-gonic/gin"
"github.com/go-go-golems/glazed/pkg/cmds"
"io"
"github.com/labstack/echo/v4"
)

// Handler wraps the normal handle method to allow rendering into a different writer,
// so that we can provide file downloads.
//
// TODO(manuel, 2024-05-07) I don't think we actually need this
type Handler interface {
Handle(c *gin.Context, w io.Writer) error
Handle(c echo.Context) error
}

type UnsupportedCommandError struct {
Expand Down
27 changes: 9 additions & 18 deletions pkg/glazed/handlers/json/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package json
import (
"bytes"
"encoding/json"
"github.com/gin-gonic/gin"
"github.com/go-go-golems/glazed/pkg/cmds"
"github.com/go-go-golems/glazed/pkg/cmds/layers"
"github.com/go-go-golems/glazed/pkg/cmds/middlewares"
Expand All @@ -12,8 +11,7 @@ import (
"github.com/go-go-golems/glazed/pkg/middlewares/row"
"github.com/go-go-golems/parka/pkg/glazed/handlers"
middlewares2 "github.com/go-go-golems/parka/pkg/glazed/middlewares"
"github.com/rs/zerolog/log"
"io"
"github.com/labstack/echo/v4"
"net/http"
)

Expand Down Expand Up @@ -44,7 +42,7 @@ func WithMiddlewares(middlewares ...middlewares.Middleware) QueryHandlerOption {

var _ handlers.Handler = (*QueryHandler)(nil)

func (h *QueryHandler) Handle(c *gin.Context, writer io.Writer) error {
func (h *QueryHandler) Handle(c echo.Context) error {
description := h.cmd.Description()
parsedLayers := layers.NewParsedLayers()

Expand All @@ -58,9 +56,10 @@ func (h *QueryHandler) Handle(c *gin.Context, writer io.Writer) error {
return err
}

c.Header("Content-Type", "application/json")
c.Response().Header().Set("Content-Type", "application/json")
c.Response().WriteHeader(http.StatusOK)

ctx := c.Request.Context()
ctx := c.Request().Context()
switch cmd := h.cmd.(type) {
case cmds.WriterCommand:
buf := bytes.Buffer{}
Expand All @@ -74,7 +73,7 @@ func (h *QueryHandler) Handle(c *gin.Context, writer io.Writer) error {
}{
Data: buf.String(),
}
encoder := json.NewEncoder(writer)
encoder := json.NewEncoder(c.Response())
encoder.SetIndent("", " ")
err = encoder.Encode(foo)
if err != nil {
Expand All @@ -89,7 +88,7 @@ func (h *QueryHandler) Handle(c *gin.Context, writer io.Writer) error {

// remove table middlewares because we are a streaming handler
gp.ReplaceTableMiddleware()
gp.AddRowMiddleware(row.NewOutputMiddleware(json2.NewOutputFormatter(), writer))
gp.AddRowMiddleware(row.NewOutputMiddleware(json2.NewOutputFormatter(), c.Response()))

if err != nil {
return err
Expand Down Expand Up @@ -121,15 +120,7 @@ func (h *QueryHandler) Handle(c *gin.Context, writer io.Writer) error {
func CreateJSONQueryHandler(
cmd cmds.Command,
options ...QueryHandlerOption,
) gin.HandlerFunc {
) echo.HandlerFunc {
handler := NewQueryHandler(cmd, options...)
return func(c *gin.Context) {
err := handler.Handle(c, c.Writer)
if err != nil {
log.Error().Err(err).Msg("failed to handle query")
c.JSON(http.StatusInternalServerError, gin.H{
"error": err.Error(),
})
}
}
return handler.Handle
}
Loading

0 comments on commit bd7874e

Please sign in to comment.