Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
Brandon Github
@lordnynex
// StaticMiddleware returns a middleware func
func StaticMiddleware(box *rice.Box) echo.MiddlewareFunc {
    return func(next echo.HandlerFunc) echo.HandlerFunc {
        return func(c echo.Context) (err error) {
            log.Info("BREAK1")
            if err = next(c); err != nil {
                log.Info("BREAK2")
                if he, ok := err.(*echo.HTTPError); ok {
                    log.Info("BREAK3")
                    if he.Code == http.StatusNotFound {
                        log.Info("BREAK4")
                        return c.File("index.html")
                    }
                }
            }
            return
        }
    }
}
For some reason if err = next(c); err != nil { never seems to return an err on 404
Is that expected behavior?
    box := frontend.GetBox()
    assetHandler := http.FileServer(box.HTTPBox())
    h.server.Use(middleware.StaticMiddleware(box))
    h.server.GET("/*", echo.WrapHandler(assetHandler))
Am I doing anything obviously wrong?
Brandon Github
@lordnynex
I've spent way too long on this. Making me crazy
I know I've done this before with angular. I wonder if it's a problem with v4?
kissinsight
@kissinsight
Please suggest an authentication package like passportjs for golang?
longlnk
@longlnk
Hi, Can Echo support caching on Reverse Proxy?
longlnk
@longlnk
I want use caching on http request and respone :D
undeadindustries
@undeadindustries
I'm sure you guys get this question a lot. For autoTLS, how do I fix: echo: http: TLS handshake error from 127.0.0.1:60078: acme/autocert: unable to satisfy "https://acme-v02.api.letsencrypt.org/acme/authz-v3/1781773148" for domain "local.mydomain.com": no viable challenge type found
echo: http: TLS handshake error from 127.0.0.1:60079: acme/autocert: missing certificate
(local.mydomain.com) is a real domain with an A record to 127.0.0.1)
Yuval Meshorer
@MeshyIce
Hey everyone, I'm trying to check the Content-Type value of a request and perform different actions based on the value.
My problem is that the Content-Type can be something like "application/json " (notice the space) but also something similar to "application/json; charset=UTF-8". Is there a built-in way to check the application type in the header's value? Meaning, to check if the application type satisfies application/json?
Or do I have to do something like this:
contentTypes := c.Request().Header.Get("Content-Type")
for _, contentType := range strings.Split(contentTypes, ";") {
    if strings.TrimSpace(contentType) == "application/json" {
        fmt.Println("Content type is JSON!")
    } else if strings.TrimSpace(contentType) == "application/zip" {
        fmt.Println("Content type is ZIP!")
    } else {
        fmt.Println("Content Type is unknown!")
    }
}
Yuval Meshorer
@MeshyIce
Never mind, an easier solution would be to use strings.HasPrefix :)
Michael Aldridge
@the-maldridge

I'm trying to do this:

return c.Redirect(http.StatusUnauthorized, "/auth/login?next=/entity/create")

and getting "Internal Server Error". Is StatusUnauthorized treated specially by echo in some way that would make this fail?

Bitcollage
@SerkanSipahi

I just want to know why it is not possible to use multiple middlewares in a handler! Maybe it is a Golang thing and i dont know it. I could not find anything in the web. Depending on the order in which the middlewares are used, "a" or "b" is nil.

This is the error message: interface conversion: echo.Context is *foo.MiddlewareContext, not *bar.MiddlewareContext!

func MyHandler(tr tracking.Tracker) func(c echo.Context) error {
    return func(c echo.Context) error {
        a := c.(*foo.MiddlewareContext)
        b := c.(*bar.MiddlewareContext) // this is nil
...
...
...

I think you can register multiple middlewares but type assert only one per handler!

What im doing wrong?

Bitcollage
@SerkanSipahi
I can confirm, this is a Golang thing!
Nan0
@NanoNik
Hi everyone, I faced problem with Static files routing, when i try to download some files i receive premature EOF exception, file is valid, server returns 200, application is proxied using nginx and cloudflare (File cannot be downloaded even using browser)
This message was deleted
router.Static("/clients", "./Clients")
router.Static("/loader", "./loader")
Nginx reverse proxy:
    location / {
        proxy_pass http://Launcher:3000;
        proxy_http_version    1.1;
        proxy_cache_bypass    $http_upgrade
        proxy_set_header Upgrade            $http_upgrade;
        proxy_set_header Connection         "upgrade";
        proxy_set_header Host                $host;
        proxy_set_header X-Real-IP            $remote_addr;
        proxy_set_header X-Forwarded-For    $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto    $scheme;
        proxy_set_header X-Forwarded-Host    $host;
        proxy_set_header X-Forwarded-Port    $server_port;
    }
Miguel Filipe
@msf
Hello everyone, I'm migrating a python http+json webservice to echo and am looking on how to read/use the url provided IDs that come in the form of : "/stuff/:id/bar" ..
I need to use these on POST requests that hold more data on the json body
Michael Aldridge
@the-maldridge
c.Param
@msf
halvarflake
@halvarflake_twitter
good day - I have a bit of a newb question: When accepting non-path parameters, using c.Bind() works great for me -- what about path parameters, though? What is the "idiomatic" way of parsing them? Is there something like Bind, or is it c.Param("name") the right way to go?
Miguel Filipe
@msf

So, I have code like:

func (h *handler) MyAPI(c echo.Context) error {
  err = h.foo.HandleAPI(...)
  if err != nil {...}
  err = h.bar.FinalizeAndSave(...)
  ....
}

My question is: should HandleAPI() and FinalizeAndSave() received and have c echo.Context as a first argument to propagate the context? is this pattern recomended?

Mohammad Fatemi
@smf8
Hi.
Can anyone suggest any repository for rest API examples with good structure?
with echo is it idiomatic to have API files packaged inside "handler", "auth", "router"?
Mohammed Abubakar
@moh-abk
@smf8 this is my usual layout which sorta follows clean architecture
.
├── Gopkg.lock
├── Gopkg.toml
├── README.md
├── config
├── controllers
├── database
├── handlers
├── main.go
├── middleware
├── models
├── repository
├── routes
├── utils
└── vendor
Mehran Poursadeghi
@mehran-prs
Hi, give Mongo Go Models(mgm) a try with echo, it's model-based ODM for MongoDB.
pindamonhangaba
@pindamonhangaba
how to use both jwt & basic auth in a group?
Alper Hankendi
@alperhankendi
Hi, give Mongo Go Models(mgm) a try with echo, it's model-based ODM for MongoDB.
trying to get package but some internal package not allowed to download. many thanks bro it seems very helpfull
src/github.com/kamva/mgm/connection.go:6:2: use of internal package github.com/Kamva/mgm/internal/util not allowed
Zrss
@zrss
hi, all. i'm a fresh man in echo. currently, i use echo for impl the rest api server, and use the annotation of struct for validating (such as required and max), this works well in my common case, but now i want to distinguish the create and put api, i.e. some fields is required in create api but in put api they aren't ... anyone know the best practice about this problem
Mehran Poursadeghi
@mehran-prs
@zrss Define two struct one contains fields for post method, another for put method, on each request use its struct to validate.
Zrss
@zrss
@mehran-prs , thx Poursadeghi ... actually, i do it by u said, but it is not elegant, as create and put api operate the same struct (resource) in REST api design ...
Mehran Poursadeghi
@mehran-prs
@zrss by defining two struct keeping everything clean (maybe later defining another field that need to be in just one of request method fields), but If you don't want to use two structs, use https://github.com/go-ozzo/ozzo-validation , it doesn't using tags to validate, defining a validate method on your struct and then you can check request method and relative to it, defining your rules.
OpoOpo
@OpoOpo
Hi I was wondering if there is a way to use grpc on the same port as echo ?
Thank you
OpoOpo
@OpoOpo
In terms of use https://github.com/grpc-ecosystem/grpc-gateway , do you thing that it is possible to achive this throught reverse proxy ?
Robert Vrabel
@robertvrabel
Hello! I'm trying to extract a route to a func in a controllers/hello.go file. I'm getting this error and not fully understand why the type doesn't match? ./server.go:21:8: cannot use controllers.Hello (type func("github.com/labstack/echo".Context) error) as type "github.com/labstack/echo/v4".HandlerFunc in argument to e.GET
using e.GET("/", controllers.Hello)
Mehran Poursadeghi
@mehran-prs
@robertvrabel import "github.com/labstack/echo/v4" in your handler's file and use v4 Context
Mehran Poursadeghi
@mehran-prs
Hi, I wrote an article about Echo and Mongo Go Models(mgm), Read it and give me feedback about using Mongo Go Models(mgm) with Echo :)
Robert Vrabel
@robertvrabel
@mehran-prs Thank you so much! My IDE imported it without the v4. I was so confused. Really appreciate it!
Mehran Poursadeghi
@mehran-prs
You're welcome @robertvrabel :)
Manuel Vargas Evans
@mvargasevans
Hi @Nexvelius
Would you mind sharing what you end up doing when dealing with your reverse proxy question?
Ricardo Leon
@Manghud
Hello everyone! I'm trying to make a global object be accessible to each incoming request. I tried injecting it into context when starting the server (context.Set) but it is nil when I try to read it from within a request context with context.Get. Should I create a custom context that runs custom middleware to inject the global object?
deranjer
@deranjer
Hello, I'm trying to serve my echo application behind an nginx proxy... but as a subdirectory (i.e. https://domain.com/echoapp). To do this I think I need to set a base URL somewhere... do I use a middleware to generate a prefix for all routes, or is there a standard way of doing this?
Alper Hankendi
@alperhankendi
@deranjer check Group section the route with common prefix can be grouped to define a new sub-router.
https://echo.labstack.com/guide/routing
somethink like;
g := e.Group("/echoapp")
g.GET("/", getUser)
deranjer
@deranjer
@alperhankendi Thanks! After experimenting, realized I have a much more complex problem. I'm using Echo to serve a react frontend, and when I attempt to connect I get an error from my proxy saying it can't find any of the files referenced in the index.html, so it isn't passing the proxy url over correctly? If I change it to a subdomain proxy (https://echoapp.domain.com) it does find the files, but I get mixed content errors. So in my react app I can set my base URL to be the https URL and it works fine, but can't figure out how to do subdirectory proxy. However, I think subdomain proxy will have to do
Taleeb Midi
@tmidi
Hi Everyone, Any example for using LDAP with Echo?