github.com/kyma-incubator/compass/components/director@v0.0.0-20230623144113-d764f56ff805/internal/dataloaders/formationConstraintLoaders.go (about) 1 //go:generate go run github.com/vektah/dataloaden FormationConstraintLoader ParamFormationConstraint []*github.com/kyma-incubator/compass/components/director/pkg/graphql.FormationConstraint 2 3 package dataloader 4 5 import ( 6 "context" 7 "net/http" 8 "time" 9 10 "github.com/kyma-incubator/compass/components/director/pkg/graphql" 11 ) 12 13 const loadersKeyFormationConstraint contextKey = "dataloadersFormationConstraint" 14 15 // FormationConstraintLoaders missing godoc 16 type FormationConstraintLoaders struct { 17 FormationConstraintByID FormationConstraintLoader 18 } 19 20 // ParamFormationConstraint missing godoc 21 type ParamFormationConstraint struct { 22 ID string 23 Ctx context.Context 24 } 25 26 // HandlerFormationConstraint missing godoc 27 func HandlerFormationConstraint(fetchFunc func(keys []ParamFormationConstraint) ([][]*graphql.FormationConstraint, []error), maxBatch int, wait time.Duration) func(next http.Handler) http.Handler { 28 return func(next http.Handler) http.Handler { 29 return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { 30 ctx := context.WithValue(r.Context(), loadersKeyFormationConstraint, &FormationConstraintLoaders{ 31 FormationConstraintByID: FormationConstraintLoader{ 32 maxBatch: maxBatch, 33 wait: wait, 34 fetch: fetchFunc, 35 }, 36 }) 37 r = r.WithContext(ctx) 38 next.ServeHTTP(w, r) 39 }) 40 } 41 } 42 43 // FormationTemplateFor missing godoc 44 func FormationTemplateFor(ctx context.Context) *FormationConstraintLoaders { 45 return ctx.Value(loadersKeyFormationConstraint).(*FormationConstraintLoaders) 46 }