(req *http.Request, bucketName string)
| 138 | } |
| 139 | |
| 140 | func processRemapRequest(req *http.Request, bucketName string) ( |
| 141 | *cbgt.IndexDefs, error) { |
| 142 | requestBody, err := ioutil.ReadAll(req.Body) |
| 143 | if err != nil { |
| 144 | return nil, fmt.Errorf("failed to read request body, err: %v", err) |
| 145 | } |
| 146 | |
| 147 | indexDefs := &cbgt.IndexDefs{} |
| 148 | if len(requestBody) > 0 { |
| 149 | err := json.Unmarshal(requestBody, indexDefs) |
| 150 | if err != nil { |
| 151 | return nil, fmt.Errorf("requestBody: %s, json unmarshal err: %v", requestBody, err) |
| 152 | } |
| 153 | } |
| 154 | |
| 155 | if len(indexDefs.IndexDefs) == 0 { |
| 156 | return nil, fmt.Errorf("requestBody: no index definitions parsed") |
| 157 | } |
| 158 | |
| 159 | queryParams := req.URL.Query() |
| 160 | params := queryParams.Get("remap") |
| 161 | mapingRules, err := parseMappingParams(params) |
| 162 | if err != nil { |
| 163 | return nil, err |
| 164 | } |
| 165 | indexDefs, err = remapIndexDefinitions(indexDefs, mapingRules, bucketName) |
| 166 | if err != nil { |
| 167 | return nil, fmt.Errorf("index remapping error: %v", err) |
| 168 | } |
| 169 | |
| 170 | return indexDefs, nil |
| 171 | } |
| 172 | |
| 173 | func parseMappingParams(params string) (map[string]string, error) { |
| 174 | rv := make(map[string]string) |
no test coverage detected