MCPcopy Create free account
hub / github.com/easyp-tech/server / ServeGetModules

Method ServeGetModules

internal/connect/commits.go:1111–1244  ·  view source on GitHub ↗

ServeGetModules handles v1/v1beta1 ModuleService/GetModules.

(w http.ResponseWriter, r *http.Request)

Source from the content-addressed store, hash-verified

1109
1110// ServeGetModules handles v1/v1beta1 ModuleService/GetModules.
1111func (h *commitServiceHandler) ServeGetModules(w http.ResponseWriter, r *http.Request) {
1112 if r.Method != http.MethodPost {
1113 h.logHandlerError(r, w, "method not allowed", http.StatusMethodNotAllowed)
1114 return
1115 }
1116
1117 body, err := io.ReadAll(r.Body)
1118 if err != nil {
1119 h.badRequest(r, w, "reading body", slog.String("read_error", err.Error()))
1120 return
1121 }
1122
1123 // Parse GetModulesRequest: repeated ModuleRef module_refs = 1
1124 // ModuleRef { oneof value { string id = 1; Name name = 2; } }
1125 // Name { string owner = 1; string module = 2; }
1126 h.commitMu.RLock()
1127 // Build moduleID → "owner/module" lookup
1128 moduleLookup := make(map[string]string, len(h.infoCache))
1129 for k, v := range h.infoCache {
1130 moduleLookup[v.moduleID] = k
1131 }
1132 h.commitMu.RUnlock()
1133
1134 h.hlog(r).LogAttrs(r.Context(), slog.LevelInfo, "handler decision",
1135 slog.String("handler", "ServeGetModules"),
1136 slog.String("procedure", "ModuleService/GetModules"),
1137 slog.String("branch", "request_received"),
1138 slog.Int("body_bytes", len(body)),
1139 slog.Int("info_cache_size", len(h.infoCache)),
1140 slog.String("raw_body_hex", hex.EncodeToString(body)),
1141 )
1142
1143 type moduleKey struct {
1144 owner string
1145 module string
1146 }
1147 var keys []moduleKey
1148 var refsSeen, refsMatched, refsRejected int
1149 msg := body
1150 for len(msg) > 0 {
1151 num, typ, n := protowire.ConsumeTag(msg)
1152 if n < 0 {
1153 break
1154 }
1155 msg = msg[n:]
1156 if num == 1 && typ == protowire.BytesType {
1157 v, mLen := protowire.ConsumeBytes(msg)
1158 msg = msg[mLen:]
1159 refsSeen++
1160 if key := parseModuleRefByID(v, moduleLookup); key != nil {
1161 keys = append(keys, *key)
1162 refsMatched++
1163 h.hlog(r).LogAttrs(r.Context(), slog.LevelInfo, "handler decision",
1164 slog.String("handler", "ServeGetModules"),
1165 slog.String("procedure", "ModuleService/GetModules"),
1166 slog.String("branch", "parse_module_ref"),
1167 slog.String("outcome", "matched"),
1168 slog.Int("ref_bytes", len(v)),

Callers

nothing calls this directly

Calls 8

logHandlerErrorMethod · 0.95
badRequestMethod · 0.95
hlogMethod · 0.95
parseModuleRefByIDFunction · 0.85
buildModuleFunction · 0.85
ErrorMethod · 0.80
WriteMethod · 0.80
StringMethod · 0.45

Tested by

no test coverage detected