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

Function sourceNamesForAlias

rest_auth.go:172–210  ·  view source on GitHub ↗

--------------------------------------------------------

(name string, indexDefsByName map[string]*cbgt.IndexDef,
	depth int)

Source from the content-addressed store, hash-verified

170// --------------------------------------------------------
171
172func sourceNamesForAlias(name string, indexDefsByName map[string]*cbgt.IndexDef,
173 depth int) ([]string, error) {
174 if depth > 50 {
175 return nil, errAliasExpansionTooDeep
176 }
177
178 var rv []string
179
180 indexDef, exists := indexDefsByName[name]
181 if exists && indexDef != nil && indexDef.Type == "fulltext-alias" {
182 aliasParams, err := parseAliasParams(indexDef.Params)
183 if err != nil {
184 return nil, fmt.Errorf("error expanding fulltext-alias: %v", err)
185 }
186 for aliasIndexName := range aliasParams.Targets {
187 aliasIndexDef, exists := indexDefsByName[aliasIndexName]
188 // if alias target doesn't exist, do nothing
189 if exists {
190 if aliasIndexDef.Type == "fulltext-alias" {
191 // handle nested aliases with recursive call
192 nestedSources, err := sourceNamesForAlias(aliasIndexName,
193 indexDefsByName, depth+1)
194 if err != nil {
195 return nil, err
196 }
197 rv = append(rv, nestedSources...)
198 } else {
199 sourceNames, err := getSourceNamesFromIndexDef(aliasIndexDef)
200 if err != nil {
201 return nil, err
202 }
203 rv = append(rv, sourceNames...)
204 }
205 }
206 }
207 }
208
209 return rv, nil
210}
211
212func getSourceNamesFromIndexDef(indexDef *cbgt.IndexDef) ([]string, error) {
213 if len(indexDef.Params) > 0 {

Callers 4

sourceNamesFromReqFunction · 0.85
findCouchbaseSourceNamesFunction · 0.85
ServeHTTPMethod · 0.85
TestSourceNamesForAliasFunction · 0.85

Calls 2

parseAliasParamsFunction · 0.85

Tested by 1

TestSourceNamesForAliasFunction · 0.68