22 lines
446 B
Go
22 lines
446 B
Go
package handlers
|
|
|
|
import "context"
|
|
import "net/http"
|
|
|
|
import "codit/internal/db"
|
|
import "codit/internal/middleware"
|
|
|
|
func (api *API) store(r *http.Request) *db.Store {
|
|
if r == nil { return api.Store }
|
|
return api.storeContext(r.Context())
|
|
}
|
|
|
|
func (api *API) storeContext(ctx context.Context) *db.Store {
|
|
var store *db.Store
|
|
var ok bool
|
|
|
|
store, ok = middleware.StoreFromContext(ctx)
|
|
if ok && store != nil { return store }
|
|
return api.Store
|
|
}
|