Skip to content

question: how to pass a pre-allocated Context to Echo.ServeHTTP? #568

Description

@genez

I am build a multi-subdomain HTTP service following the example using an host map
I would like to pass my datastore object into the context but the ServeHTTP func uses a newly-allocated one so it never goes down to my handler

Is there any work-around?
Should I use a global datastore object?

Thanks

// Server
    e := echo.New()
    e.Any("/*", func(c echo.Context) (err error) {
        req := c.Request()
        res := c.Response()
        host := hosts[req.Host()]

        if host == nil {
            err = echo.ErrNotFound
        } else {
            c.Set("DataStore", persistence.DataStore) <-- HERE IS MY ISSUE
            host.Echo.ServeHTTP(req, res)
        }

        return err
    })
    e.Run(standard.New(":8080"))

Metadata

Metadata

Assignees

Labels

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions