MCPcopy Create free account
hub / github.com/couchbase/cbft / processRemapRequest

Function processRemapRequest

rest_backup_restore.go:140–171  ·  view source on GitHub ↗
(req *http.Request, bucketName string)

Source from the content-addressed store, hash-verified

138}
139
140func 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
173func parseMappingParams(params string) (map[string]string, error) {
174 rv := make(map[string]string)

Callers 2

ServeHTTPMethod · 0.85
ServeHTTPMethod · 0.85

Calls 5

parseMappingParamsFunction · 0.85
remapIndexDefinitionsFunction · 0.85
UnmarshalMethod · 0.80
GetMethod · 0.80
QueryMethod · 0.45

Tested by

no test coverage detected