in frontend/mux.go [240:297]
func (m *BuildMux) list(ctx context.Context, client gwclient.Client, target string) (*gwclient.Result, error) {
var ls bktargets.List
var check []string
if target == "" {
check = maps.Keys(m.handlers)
} else {
// Use the target as a filter so the response only includes routes that are underneath the target
check = append(check, target)
}
slices.Sort(check)
bklog.G(ctx).WithField("checks", check).Debug("Checking targets")
for _, t := range check {
ctx := bklog.WithLogger(ctx, bklog.G(ctx).WithField("check", t))
bklog.G(ctx).Debug("Lookup target")
matched, h, err := m.lookupTarget(ctx, t)
if err != nil {
bklog.G(ctx).WithError(err).Warn("Error looking up target, skipping")
continue
}
ctx = bklog.WithLogger(ctx, bklog.G(ctx).WithField("matched", matched))
bklog.G(ctx).Debug("Matched target")
if h.t != nil {
t := *h.t
// We have the target info, we can use this directly
ls.Targets = append(ls.Targets, t)
continue
}
bklog.G(ctx).Info("No target info, calling handler")
// No target info, so call the handler to get the info
// This calls the route handler.
// The route handler must be setup to handle the subrequest
// Today we assume all route handers are setup to handle the subrequest.
res, err := h.f(ctx, maybeSetDalecTargetKey(trimTargetOpt(client, matched), matched))
if err != nil {
bklog.G(ctx).Errorf("%+v", err)
return nil, err
}
var _ls bktargets.List
if err := unmarshalResult(res, &_ls); err != nil {
return nil, err
}
for _, t := range _ls.Targets {
t.Name = path.Join(matched, t.Name)
ls.Targets = append(ls.Targets, t)
}
}
return ls.ToResult()
}