MCPcopy
hub / github.com/perkeep/perkeep / currentStatus

Method currentStatus

pkg/server/status.go:157–211  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

155}
156
157func (sh *StatusHandler) currentStatus() *status {
158 res := &status{
159 Version: buildinfo.Summary(),
160 GoInfo: fmt.Sprintf("%s %s/%s cgo=%v", runtime.Version(), runtime.GOOS, runtime.GOARCH, cgoEnabled),
161 Storage: make(map[string]storageStatus),
162 Sync: make(map[string]syncStatus),
163 }
164 if v := os.Getenv("CAMLI_FAKE_STATUS_ERROR"); v != "" {
165 res.addError(v, "/status/#fakeerror")
166 }
167 _, hi, err := sh.handlerFinder.FindHandlerByType("root")
168 if err != nil {
169 res.addError(fmt.Sprintf("Error finding root handler: %v", err), "")
170 return res
171 }
172 rh := hi.(*RootHandler)
173 res.rootPrefix = rh.Prefix
174
175 if pfx, h, err := sh.handlerFinder.FindHandlerByType("importer"); err == nil {
176 res.importerRoot = pfx
177 as := h.(interface {
178 AccountsStatus() (interface{}, []camtypes.StatusError)
179 })
180 var errs []camtypes.StatusError
181 res.ImporterAccounts, errs = as.AccountsStatus()
182 res.Errors = append(res.Errors, errs...)
183 }
184
185 types, handlers := sh.handlerFinder.AllHandlers()
186
187 // Sync
188 for pfx, h := range handlers {
189 sh, ok := h.(*SyncHandler)
190 if !ok {
191 continue
192 }
193 res.Sync[pfx] = sh.currentStatus()
194 }
195
196 // Storage
197 for pfx, typ := range types {
198 if !strings.HasPrefix(typ, "storage-") {
199 continue
200 }
201 h := handlers[pfx]
202 _, isIndex := h.(*index.Index)
203 res.Storage[pfx] = storageStatus{
204 Type: strings.TrimPrefix(typ, "storage-"),
205 Primary: pfx == rh.BlobRoot,
206 IsIndex: isIndex,
207 }
208 }
209
210 return res
211}
212
213func (sh *StatusHandler) serveStatusJSON(rw http.ResponseWriter, req *http.Request) {
214 httputil.ReturnJSON(rw, sh.currentStatus())

Callers 3

InitHandlerMethod · 0.95
serveStatusJSONMethod · 0.95
serveStatusHTMLMethod · 0.95

Calls 6

addErrorMethod · 0.95
SummaryFunction · 0.92
AccountsStatusMethod · 0.80
HasPrefixMethod · 0.80
FindHandlerByTypeMethod · 0.65
AllHandlersMethod · 0.65

Tested by

no test coverage detected