package http import ( "context" "net/http" "hyapp/services/gateway-service/internal/appconfig" ) // appConfigReader 是 gateway 对后台 App 配置的只读依赖。 type appConfigReader interface { ListH5Links(ctx context.Context) ([]appconfig.H5Link, error) } // listH5Links 返回后台 APP配置/H5配置 中维护的 H5 入口地址。 func (h *Handler) listH5Links(writer http.ResponseWriter, request *http.Request) { if h.appConfigReader == nil { // H5 地址来自后台配置表;未注入 reader 时不能返回空假数据。 writeError(writer, request, http.StatusBadGateway, codeUpstreamError, "upstream service error") return } items, err := h.appConfigReader.ListH5Links(request.Context()) if err != nil { // 配置读取失败属于服务端依赖异常,客户端只需要根据 request_id 排查。 writeError(writer, request, http.StatusBadGateway, codeUpstreamError, "upstream service error") return } writeOK(writer, request, map[string]any{"items": items, "total": len(items)}) }