()
| 155 | } |
| 156 | |
| 157 | func (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 | |
| 213 | func (sh *StatusHandler) serveStatusJSON(rw http.ResponseWriter, req *http.Request) { |
| 214 | httputil.ReturnJSON(rw, sh.currentStatus()) |
no test coverage detected