Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • 06:15
    cyberkryption closed #2075
  • 06:15
    cyberkryption commented #2075
  • 05:32
    ftamhar starred labstack/echo
  • 05:31
    chenjunlinabc starred labstack/echo
  • 02:31
    yqlbu starred labstack/echo
  • Jan 23 23:06
    lammel commented #2044
  • Jan 23 22:14
    lammel commented #2049
  • Jan 23 21:20
    codecov[bot] commented #2049
  • Jan 23 21:18
    lammel commented #2072
  • Jan 23 20:47
    aldas commented #2075
  • Jan 23 20:38
    codecov[bot] commented #2072
  • Jan 23 20:37

    aldas on master

    Add pagoda to the README. (compare)

  • Jan 23 20:37
    aldas closed #2077
  • Jan 23 20:29
    pllffrd starred labstack/echo
  • Jan 23 20:21

    aldas on master

    Add Retry-After header constant (compare)

  • Jan 23 20:21
    aldas closed #2078
  • Jan 23 17:10
    lammel commented #2064
  • Jan 23 16:11
    kelindar starred labstack/echo
  • Jan 23 12:44
    barakplasma starred labstack/echo
  • Jan 23 09:29
    josepdcs starred labstack/echo
Kamol Mavlonov
@kamoljan
nope
Only this
e := echo.New()
    e.Use(middleware.LoggerWithConfig(middleware.LoggerConfig{
Kamol Mavlonov
@kamoljan
I disabled all middleware and DisableHTTP2=true, but still this chunked response.
Martti T.
@aldas
there is nothing special related to chunked in echo code. This is probably related to request headers and some logic inside go http package.
does that request have Content-Length header?
4 replies
José María Martín
@jose-martin-m
Hi! I'm using echo with oapi validate middleware to check incoming request parameters against a regex in an OpenApi specification file. When a parameter does not match the regex a message it's shown with the correct regex for that parameter. The problem I'm having is that the slashes in the regex string are escaped multiple times. I think that when opai_validate generates the error message it prints the regex with %q so the single slash is escaped there. And then when echo prints the message the same thing happens and each slash is escaped again, making a single slash into four. Does anyone have an idea on how to deal with this?
Martti T.
@aldas
and maybe another breakpoint here https://github.com/labstack/echo/blob/c6f0c667f145b5e5347ba812c9de5a5a4280bac5/echo.go#L371 and you probably will see here things go south
If you do not have experience with debugger then maybe https://www.digitalocean.com/community/tutorials/debugging-go-code-with-visual-studio-code helps. assuming you are using vscode.
José María Martín
@jose-martin-m
Thank you for your response @aldas , will take a look when I can and report back
José María Martín
@jose-martin-m
Part of the problem seems to be Echo returns the string raw without processing its characters...? I'm not entirely sure. But modifying the error message and inserting tab characters \t makes those characters appear directly in the response instead of being processed, so I'm guessing something happens there and an escaped backslash \\ in the string is returned as-is
Martti T.
@aldas
Assuming that error ends up in global error handler. then it is sent to client by that line https://github.com/labstack/echo/blob/c6f0c667f145b5e5347ba812c9de5a5a4280bac5/echo.go#L400 if that message is already been escaped some characters will be double escaped to be valid json string value.
José María Martín
@jose-martin-m
ohh, I see, so the JSON response needs to have the backslash escaped and that's why it appears two times
Maksimilian
@trendeeze_twitter
I am using c.JSON to return a json response, however the inner item of the response is in base64. Why would that happen?
the field that is returning as base64 is a []byte in the struct
Maksimilian
@trendeeze_twitter
alright I see, it doesn't like that, works if I use a nested struct instead of []byte
Martti T.
@aldas

see https://pkg.go.dev/encoding/json#Marshal

Array and slice values encode as JSON arrays, except that []byte encodes as a base64-encoded string, and a nil slice encodes as the null JSON value.

David Desmarais-Michaud
@davidmdm
I can't seem to find the documentation but do paths support other directives other than : ?
Does it support regexp to some degree?
Martti T.
@aldas
only : is considered as start of path parameter. path param name will be everything till next / or end of path.
Note: any param * is a special case of : and you can access any path value in handler/middleware by c.Param("*")
baldr9
@baldr9
How to use a gRPC service with echo framework. I have the same question from: https://stackoverflow.com/questions/67558481/how-to-use-grpc-with-golang-echo-framework
Martti T.
@aldas
I do not think you are able to. GRPC is binary protocol and is completely different from HTTP. There are maybe server implementation that can sniff traffic and do routing of request to GRPC or HTTP handlers.
just implement layered architecture in our application and design HTTP and GRPC handlers in your transport layer that extract their data and pass it t your business service layer.
search for "Onion Architecture" / "Hexagonal Architecture"
Martti T.
@aldas
quick googling gives me for Go https://blog.kinark.app/post/onion-architecture/ which seems decent article
1 reply
Andrey Grehov
@andreygrehov_twitter
Hello. Does Echo have some sort of a retry mechanism on panics?
I noticed a paniced request flow is being retried 3 times, can't understand why would that happen
Andrey Grehov
@andreygrehov_twitter
nvm, it's chrome's weird behavior..
Maksimilian
@trendeeze_twitter
how can I access the requestId from the context?
ali naseri
@alinaserinet
Hi dears
Why does this error occur in Echo? "Please provide valid credentials"
Matthias
@matthias:bsr.mn
[m]
hi! is it possible to use the proxy middleware to proxy a unix socket? I am getting {"message":"remote unix:///tmp/ttyd.sock unreachable, could not forward: unsupported protocol scheme \"unix\""}
Matthias
@matthias:bsr.mn
[m]
if it's not possible I'd like to open a feature request on github
Martti T.
@aldas

You could try

    proxyConf := middleware.ProxyConfig{
        // your other settings
        Transport: &http.Transport{
            DialContext: func(ctx context.Context, network, addr string) (net.Conn, error) {
                return net.Dial("unix", addr)
            },
        },
    }
    e.Use(middleware.ProxyWithConfig(proxyConf))

maybe it works.

3 replies
Matthias
@matthias:bsr.mn
[m]
panic: echo: proxy middleware requires balancer

goroutine 1 [running]:
github.com/labstack/echo/v4/middleware.ProxyWithConfig({0x1319698, {0x0, 0x0}, 0x0, 0x0, {0x0, 0x0}, {0x13641a0, 0xc00013d040}, 0x0})
    /Users/matthias/go/pkg/mod/github.com/labstack/echo/v4@v4.6.1/middleware/proxy.go:214 +0x1aa
main.main()
    /Users/matthias/apigw/server.go:62 +0x194
exit status 2
`
should I just pass an empty balancer?
with an empty balancer:
echo: http: panic serving [::1]:61352: runtime error: invalid memory address or nil pointer dereference
goroutine 6 [running]:
net/http.(*conn).serve.func1()
    /usr/local/Cellar/go/1.17.2/libexec/src/net/http/server.go:1801 +0xb9
panic({0x12b0840, 0x154adf0})
    /usr/local/Cellar/go/1.17.2/libexec/src/runtime/panic.go:1047 +0x266
net/http/httputil.NewSingleHostReverseProxy(0x0)
    /usr/local/Cellar/go/1.17.2/libexec/src/net/http/httputil/reverseproxy.go:144 +0x1d
github.com/labstack/echo/v4/middleware.proxyHTTP(0xc0000668a0, {0x13736f0, 0xc00018c460}, {0x1319778, {0x136a6a0, 0xc0000134e0}, 0x0, 0x0, {0x0, 0x0}, ...})
    /Users/matthias/go/pkg/mod/github.com/labstack/echo/v4@v4.6.1/middleware/proxy.go:279 +0x45
github.com/labstack/echo/v4/middleware.ProxyWithConfig.func1.1({0x13736f0, 0xc00018c460})
    /Users/matthias/go/pkg/mod/github.com/labstack/echo/v4@v4.6.1/middleware/proxy.go:260 +0x5d0
github.com/labstack/echo/v4.(*Echo).add.func1({0x13736f0, 0xc00018c460})
    /Users/matthias/go/pkg/mod/github.com/labstack/echo/v4@v4.6.1/echo.go:552 +0x51
github.com/labstack/echo/v4.(*Echo).ServeHTTP(0xc000014fc0, {0x136a8e0, 0xc00017e2a0}, 0xc00019e000)
    /Users/matthias/go/pkg/mod/github.com/labstack/echo/v4@v4.6.1/echo.go:662 +0x3bc
net/http.serverHandler.ServeHTTP({0xc0001917d0}, {0x136a8e0, 0xc00017e2a0}, 0xc00019e000)
    /usr/local/Cellar/go/1.17.2/libexec/src/net/http/server.go:2878 +0x43b
net/http.(*conn).serve(0xc00018c3c0, {0x136bb00, 0xc0001916e0})
    /usr/local/Cellar/go/1.17.2/libexec/src/net/http/server.go:1929 +0xb08
created by net/http.(*Server).Serve
    /usr/local/Cellar/go/1.17.2/libexec/src/net/http/server.go:3033 +0x4e8
Martti T.
@aldas
you need balancer. What that Transport.DialContext does is that it will use unix socket instead of tcp for initiating the connection.
4 replies
Matthias
@matthias:bsr.mn
[m]
will try later
Yeah I am very new to go. Literally just started today
Thanks for the pointers
Martti T.
@aldas
np
Matthias
@matthias:bsr.mn
[m]

when proxying multiple things like:

serverA -> /
serverB -> /api

can I make serverA not overwrite serverB on /api? Because I can't figure it out haha

Matthias
@matthias:bsr.mn
[m]
ah nevermind I am blind
skipper seems to work for this purpose
Berke Soysal
@BerkeSoysal
is it possible to take multiple http parameters with the same identifier?
1 reply
Matthias
@matthias:bsr.mn
[m]
Request query returns an array always
6 replies
Matthias
@matthias:bsr.mn
[m]

question. I am trying to add a custom middleware which changes both method and path (I know there are existing middlewares for both and I checked their source)

        req := c.Request()
        req.Method = "PUT"
        path := req.URL.Path
        url, _ := req.URL.Parse(path + "/9")
        req.URL = url

This succeeds in changing the method, but it fails changing the path, any idea what's up with that?

Matthias
@matthias:bsr.mn
[m]
just to be clear, I am using my middleware with e.Preas recommended
Matthias
@matthias:bsr.mn
[m]
Nevermind. Worked around it another way