MCPcopy Create free account
hub / github.com/couchbase/sync_gateway / CallValidateFunction

Method CallValidateFunction

db/event.go:169–190  ·  view source on GitHub ↗

Calls a jsEventFunction returning bool.

(ctx context.Context, event Event)

Source from the content-addressed store, hash-verified

167
168// Calls a jsEventFunction returning bool.
169func (ef *JSEventFunction) CallValidateFunction(ctx context.Context, event Event) (bool, error) {
170
171 result, err := ef.CallFunction(ctx, event)
172 if err != nil {
173 return false, err
174 }
175
176 switch result := result.(type) {
177 case bool:
178 return result, nil
179 case string:
180 boolResult, err := strconv.ParseBool(result)
181 if err != nil {
182 return false, err
183 }
184 return boolResult, nil
185 default:
186 base.WarnfCtx(ctx, "Event validate function returned non-boolean result %T %v", result, result)
187 return false, errors.New("Validate function returned non-boolean value.")
188 }
189
190}

Callers 2

TestCallValidateFunctionFunction · 0.95
HandleEventMethod · 0.80

Calls 2

CallFunctionMethod · 0.95
WarnfCtxFunction · 0.92

Tested by 1

TestCallValidateFunctionFunction · 0.76