- var indexResp []byte
- var reader io.Reader
-
- switch req.Method {
- case "GET":
- for uuid := range kc.LocalRoots() {
- reader, err = kc.GetIndex(uuid, prefix)
- if err != nil {
- break
- }
-
- var readBytes []byte
- readBytes, err = ioutil.ReadAll(reader)
- if err != nil {
- break
- }
-
- // Got index; verify that it is complete
- // The response should be "\n" if no locators matched the prefix
- // Else, it should be a list of locators followed by a blank line
- if (!strings.HasSuffix(string(readBytes), "\n\n")) && (string(readBytes) != "\n") {
- err = errors.New("Got incomplete index")
- }
-
- // Trim the extra empty new line found in response from each server
- indexResp = append(indexResp, (readBytes[0 : len(readBytes)-1])...)
- }
-
- // Append empty line at the end of concatenation of all server responses
- indexResp = append(indexResp, ([]byte("\n"))...)
- default: