Access to store from middleware
xellDart opened this issue · comments
xell.DEV commented
Thank you very much for your example, I am following the design pattern, but I am facing a problem, I implemented a function to check data in the db in a middleware, but I do not know how to access the store from the router / middleware route, could you give me an example of how to do this?
Here is my example code:
public, err := publicKey(c)
if err != nil {
return c.JSON(http.StatusUnauthorized, utils.NewError(err))
}
secret, err := secretKey(c)
if err != nil {
return c.JSON(http.StatusUnauthorized, utils.NewError(err))
}
company := model.Company{
Keys: model.Keys{
Public: public,
Secret: secret,
},
}
resp, err := store.CompanyStore{}.GetByKeys(&company)
if err != nil {
return c.JSON(http.StatusForbidden, utils.NewError(ErrKeysInvalid))
}
c.Set("company", resp)
return next(c)