func (d *idm) initPathCache(ctx types.Context) { if !d.pathCacheEnabled() { ctx.Info("path cache initializion disabled") return } if name, ok := context.ServiceName(ctx); !ok || name == "" { ctx.Info("path cache initializion disabled; no service name in ctx") return } f := func(async bool) { ctx.WithField("async", async).Info("initializing the path cache") _, err := d.List(ctx, apiutils.NewStoreWithData(initPathCacheMap)) if err != nil { ctx.WithField("async", async).WithError(err).Error( "error initializing the path cache") } else { ctx.WithField("async", async).Debug("initialized the path cache") } } if d.pathCacheAsync() { go f(true) } else { f(false) } }
// Handle is the type's Handler function. func (h *postArgsHandler) Handle( ctx types.Context, w http.ResponseWriter, req *http.Request, store types.Store) error { reqObj := ctx.Value("reqObj") if reqObj == nil { return fmt.Errorf("missing request object") } v := reflect.ValueOf(reqObj).Elem() t := v.Type() for i := 0; i < v.NumField(); i++ { ft := t.Field(i) fv := v.Field(i).Interface() switch tfv := fv.(type) { case nil: // do nothing case map[string]interface{}: store.Set(getFieldName(ft), utils.NewStoreWithData(tfv)) default: // add it to the store store.Set(getFieldName(ft), fv) } } return h.handler(ctx, w, req, store) }