_id
stringlengths
2
7
title
stringlengths
1
118
partition
stringclasses
3 values
text
stringlengths
52
85.5k
language
stringclasses
1 value
meta_information
dict
q9500
ThresholdTripFunc
train
func ThresholdTripFunc(threshold int64) TripFunc { return func(cb *Breaker) bool { return cb.Failures() == threshold } }
go
{ "resource": "" }
q9501
ConsecutiveTripFunc
train
func ConsecutiveTripFunc(threshold int64) TripFunc { return func(cb *Breaker) bool { return cb.ConsecFailures() == threshold } }
go
{ "resource": "" }
q9502
NewPanel
train
func NewPanel() *Panel { return &Panel{ Circuits: make(map[string]*Breaker), Statter: &noopStatter{}, StatsPrefixf: defaultStatsPrefixf, lastTripTimes: make(map[string]time.Time)} }
go
{ "resource": "" }
q9503
Add
train
func (p *Panel) Add(name string, cb *Breaker) { p.panelLock.Lock() p.Circuits[name] = cb p.panelLock.Unlock() events := cb.Subscribe() go func() { for event := range events { for _, receiver := range p.eventReceivers { receiver <- PanelEvent{name, event} } switch event { case BreakerTripped: p.breakerTripped(name) case BreakerReset: p.breakerReset(name) case BreakerFail: p.breakerFail(name) case BreakerReady: p.breakerReady(name) } } }() }
go
{ "resource": "" }
q9504
Get
train
func (p *Panel) Get(name string) (*Breaker, bool) { p.panelLock.RLock() cb, ok := p.Circuits[name] p.panelLock.RUnlock() if ok { return cb, ok } return NewBreaker(), ok }
go
{ "resource": "" }
q9505
Subscribe
train
func (p *Panel) Subscribe() <-chan PanelEvent { eventReader := make(chan PanelEvent) output := make(chan PanelEvent, 100) go func() { for v := range eventReader { select { case output <- v: default: <-output output <- v } } }() p.eventReceivers = append(p.eventReceivers, eventReader) return output }
go
{ "resource": "" }
q9506
NewHTTPClient
train
func NewHTTPClient(timeout time.Duration, threshold int64, client *http.Client) *HTTPClient { breaker := NewThresholdBreaker(threshold) return NewHTTPClientWithBreaker(breaker, timeout, client) }
go
{ "resource": "" }
q9507
NewHostBasedHTTPClient
train
func NewHostBasedHTTPClient(timeout time.Duration, threshold int64, client *http.Client) *HTTPClient { brclient := NewHTTPClient(timeout, threshold, client) brclient.BreakerLookup = func(c *HTTPClient, val interface{}) *Breaker { rawURL := val.(string) parsedURL, err := url.Parse(rawURL) if err != nil { breaker, _ := c.Panel.Get(defaultBreakerName) return breaker } host := parsedURL.Host cb, ok := c.Panel.Get(host) if !ok { cb = NewThresholdBreaker(threshold) c.Panel.Add(host, cb) } return cb } return brclient }
go
{ "resource": "" }
q9508
NewHTTPClientWithBreaker
train
func NewHTTPClientWithBreaker(breaker *Breaker, timeout time.Duration, client *http.Client) *HTTPClient { if client == nil { client = &http.Client{} } panel := NewPanel() panel.Add(defaultBreakerName, breaker) brclient := &HTTPClient{Client: client, Panel: panel, timeout: timeout} brclient.BreakerLookup = func(c *HTTPClient, val interface{}) *Breaker { cb, _ := c.Panel.Get(defaultBreakerName) return cb } events := breaker.Subscribe() go func() { event := <-events switch event { case BreakerTripped: brclient.runBreakerTripped() case BreakerReset: brclient.runBreakerReset() } }() return brclient }
go
{ "resource": "" }
q9509
Fail
train
func (w *window) Fail() { w.bucketLock.Lock() b := w.getLatestBucket() b.Fail() w.bucketLock.Unlock() }
go
{ "resource": "" }
q9510
Success
train
func (w *window) Success() { w.bucketLock.Lock() b := w.getLatestBucket() b.Success() w.bucketLock.Unlock() }
go
{ "resource": "" }
q9511
Failures
train
func (w *window) Failures() int64 { w.bucketLock.RLock() var failures int64 w.buckets.Do(func(x interface{}) { b := x.(*bucket) failures += b.failure }) w.bucketLock.RUnlock() return failures }
go
{ "resource": "" }
q9512
Successes
train
func (w *window) Successes() int64 { w.bucketLock.RLock() var successes int64 w.buckets.Do(func(x interface{}) { b := x.(*bucket) successes += b.success }) w.bucketLock.RUnlock() return successes }
go
{ "resource": "" }
q9513
Reset
train
func (w *window) Reset() { w.bucketLock.Lock() w.buckets.Do(func(x interface{}) { x.(*bucket).Reset() }) w.bucketLock.Unlock() }
go
{ "resource": "" }
q9514
NewMutationState
train
func NewMutationState(tokens ...MutationToken) *MutationState { mt := &MutationState{} mt.Add(tokens...) return mt }
go
{ "resource": "" }
q9515
Add
train
func (mt *MutationState) Add(tokens ...MutationToken) { for _, v := range tokens { mt.addSingle(v) } }
go
{ "resource": "" }
q9516
UnmarshalJSON
train
func (mt *MutationState) UnmarshalJSON(data []byte) error { return json.Unmarshal(data, &mt.data) }
go
{ "resource": "" }
q9517
One
train
func (r *AnalyticsDeferredResultHandle) One(valuePtr interface{}) error { if !r.Next(valuePtr) { err := r.Close() if err != nil { return err } // return ErrNoResults } // Ignore any errors occurring after we already have our result err := r.Close() if err != nil { // Return no error as we got the one result already. return nil } return nil }
go
{ "resource": "" }
q9518
NewSearchSortField
train
func NewSearchSortField(field string) *SearchSortField { q := &SearchSortField{newFtsSortBase()} q.options["by"] = "field" q.options["field"] = field return q }
go
{ "resource": "" }
q9519
Type
train
func (q *SearchSortField) Type(value string) *SearchSortField { q.options["type"] = value return q }
go
{ "resource": "" }
q9520
Mode
train
func (q *SearchSortField) Mode(mode string) *SearchSortField { q.options["mode"] = mode return q }
go
{ "resource": "" }
q9521
Missing
train
func (q *SearchSortField) Missing(missing string) *SearchSortField { q.options["missing"] = missing return q }
go
{ "resource": "" }
q9522
NewSearchSortGeoDistance
train
func NewSearchSortGeoDistance(field string, lat, lon float64) *SearchSortGeoDistance { q := &SearchSortGeoDistance{newFtsSortBase()} q.options["by"] = "geo_distance" q.options["field"] = field q.options["location"] = []float64{lon, lat} return q }
go
{ "resource": "" }
q9523
Unit
train
func (q *SearchSortGeoDistance) Unit(unit string) *SearchSortGeoDistance { q.options["unit"] = unit return q }
go
{ "resource": "" }
q9524
Close
train
func (c *Cluster) Close(opts *ClusterCloseOptions) error { var overallErr error c.clusterLock.Lock() for key, conn := range c.connections { err := conn.close() if err != nil && gocbcore.ErrorCause(err) != gocbcore.ErrShutdown { logWarnf("Failed to close a client in cluster close: %s", err) overallErr = err } delete(c.connections, key) } c.clusterLock.Unlock() return overallErr }
go
{ "resource": "" }
q9525
NewMatchPhraseQuery
train
func NewMatchPhraseQuery(phrase string) *MatchPhraseQuery { q := &MatchPhraseQuery{newFtsQueryBase()} q.options["match_phrase"] = phrase return q }
go
{ "resource": "" }
q9526
NewRegexpQuery
train
func NewRegexpQuery(regexp string) *RegexpQuery { q := &RegexpQuery{newFtsQueryBase()} q.options["regexp"] = regexp return q }
go
{ "resource": "" }
q9527
NewQueryStringQuery
train
func NewQueryStringQuery(query string) *QueryStringQuery { q := &QueryStringQuery{newFtsQueryBase()} q.options["query"] = query return q }
go
{ "resource": "" }
q9528
Start
train
func (q *DateRangeQuery) Start(start string, inclusive bool) *DateRangeQuery { q.options["start"] = start q.options["inclusive_start"] = inclusive return q }
go
{ "resource": "" }
q9529
End
train
func (q *DateRangeQuery) End(end string, inclusive bool) *DateRangeQuery { q.options["end"] = end q.options["inclusive_end"] = inclusive return q }
go
{ "resource": "" }
q9530
DateTimeParser
train
func (q *DateRangeQuery) DateTimeParser(parser string) *DateRangeQuery { q.options["datetime_parser"] = parser return q }
go
{ "resource": "" }
q9531
NewConjunctionQuery
train
func NewConjunctionQuery(queries ...FtsQuery) *ConjunctionQuery { q := &ConjunctionQuery{newFtsQueryBase()} q.options["conjuncts"] = []FtsQuery{} return q.And(queries...) }
go
{ "resource": "" }
q9532
And
train
func (q *ConjunctionQuery) And(queries ...FtsQuery) *ConjunctionQuery { q.options["conjuncts"] = append(q.options["conjuncts"].([]FtsQuery), queries...) return q }
go
{ "resource": "" }
q9533
NewDisjunctionQuery
train
func NewDisjunctionQuery(queries ...FtsQuery) *DisjunctionQuery { q := &DisjunctionQuery{newFtsQueryBase()} q.options["disjuncts"] = []FtsQuery{} return q.Or(queries...) }
go
{ "resource": "" }
q9534
Or
train
func (q *DisjunctionQuery) Or(queries ...FtsQuery) *DisjunctionQuery { q.options["disjuncts"] = append(q.options["disjuncts"].([]FtsQuery), queries...) return q }
go
{ "resource": "" }
q9535
Must
train
func (q *BooleanQuery) Must(query FtsQuery) *BooleanQuery { switch val := query.(type) { case ConjunctionQuery: q.data.Must = &val case *ConjunctionQuery: q.data.Must = val default: q.data.Must = NewConjunctionQuery(val) } return q }
go
{ "resource": "" }
q9536
MustNot
train
func (q *BooleanQuery) MustNot(query FtsQuery) *BooleanQuery { switch val := query.(type) { case DisjunctionQuery: q.data.MustNot = &val case *DisjunctionQuery: q.data.MustNot = val default: q.data.MustNot = NewDisjunctionQuery(val) } return q }
go
{ "resource": "" }
q9537
ShouldMin
train
func (q *BooleanQuery) ShouldMin(min int) *BooleanQuery { q.shouldMin = min return q }
go
{ "resource": "" }
q9538
MarshalJSON
train
func (q *BooleanQuery) MarshalJSON() ([]byte, error) { if q.data.Should != nil { q.data.Should.options["min"] = q.shouldMin } bytes, err := json.Marshal(q.data) if q.data.Should != nil { delete(q.data.Should.options, "min") } return bytes, err }
go
{ "resource": "" }
q9539
NewWildcardQuery
train
func NewWildcardQuery(wildcard string) *WildcardQuery { q := &WildcardQuery{newFtsQueryBase()} q.options["wildcard"] = wildcard return q }
go
{ "resource": "" }
q9540
NewDocIdQuery
train
func NewDocIdQuery(ids ...string) *DocIdQuery { q := &DocIdQuery{newFtsQueryBase()} q.options["ids"] = []string{} return q.AddDocIds(ids...) }
go
{ "resource": "" }
q9541
AddDocIds
train
func (q *DocIdQuery) AddDocIds(ids ...string) *DocIdQuery { q.options["ids"] = append(q.options["ids"].([]string), ids...) return q }
go
{ "resource": "" }
q9542
NewBooleanFieldQuery
train
func NewBooleanFieldQuery(val bool) *BooleanFieldQuery { q := &BooleanFieldQuery{newFtsQueryBase()} q.options["bool"] = val return q }
go
{ "resource": "" }
q9543
NewTermQuery
train
func NewTermQuery(term string) *TermQuery { q := &TermQuery{newFtsQueryBase()} q.options["term"] = term return q }
go
{ "resource": "" }
q9544
NewPhraseQuery
train
func NewPhraseQuery(terms ...string) *PhraseQuery { q := &PhraseQuery{newFtsQueryBase()} q.options["terms"] = terms return q }
go
{ "resource": "" }
q9545
NewPrefixQuery
train
func NewPrefixQuery(prefix string) *PrefixQuery { q := &PrefixQuery{newFtsQueryBase()} q.options["prefix"] = prefix return q }
go
{ "resource": "" }
q9546
NewTermRangeQuery
train
func NewTermRangeQuery(term string) *TermRangeQuery { q := &TermRangeQuery{newFtsQueryBase()} q.options["term"] = term return q }
go
{ "resource": "" }
q9547
NewGeoDistanceQuery
train
func NewGeoDistanceQuery(lat, lon float64, distance string) *GeoDistanceQuery { q := &GeoDistanceQuery{newFtsQueryBase()} q.options["location"] = []float64{lon, lat} q.options["distance"] = distance return q }
go
{ "resource": "" }
q9548
NewGeoBoundingBoxQuery
train
func NewGeoBoundingBoxQuery(tlLat, tlLon, brLat, brLon float64) *GeoBoundingBoxQuery { q := &GeoBoundingBoxQuery{newFtsQueryBase()} q.options["top_left"] = []float64{tlLon, tlLat} q.options["bottom_right"] = []float64{brLon, brLat} return q }
go
{ "resource": "" }
q9549
Content
train
func (d *GetResult) Content(valuePtr interface{}) error { return DefaultDecode(d.contents, d.flags, valuePtr) }
go
{ "resource": "" }
q9550
Decode
train
func (d *GetResult) Decode(valuePtr interface{}, decode Decode) error { if decode == nil { decode = DefaultDecode } return decode(d.contents, d.flags, valuePtr) }
go
{ "resource": "" }
q9551
set
train
func (d *GetResult) set(paths []subdocPath, content interface{}, value interface{}) interface{} { path := paths[0] if len(paths) == 1 { if path.isArray { arr := make([]interface{}, 0) arr = append(arr, value) content.(map[string]interface{})[path.path] = arr } else { if _, ok := content.([]interface{}); ok { elem := make(map[string]interface{}) elem[path.path] = value content = append(content.([]interface{}), elem) } else { content.(map[string]interface{})[path.path] = value } } return content } if path.isArray { // TODO: in the future consider an array of arrays if cMap, ok := content.(map[string]interface{}); ok { cMap[path.path] = make([]interface{}, 0) cMap[path.path] = d.set(paths[1:], cMap[path.path], value) return content } } else { if arr, ok := content.([]interface{}); ok { m := make(map[string]interface{}) m[path.path] = make(map[string]interface{}) content = append(arr, m) d.set(paths[1:], m[path.path], value) return content } cMap, ok := content.(map[string]interface{}) if !ok { // this isn't possible but the linter won't play nice without it } cMap[path.path] = make(map[string]interface{}) return d.set(paths[1:], cMap[path.path], value) } return content }
go
{ "resource": "" }
q9552
DecodeAt
train
func (lir *LookupInResult) DecodeAt(idx int, valuePtr interface{}, decode Decode) error { if idx > len(lir.contents) { return errors.New("the supplied index was invalid") } if decode == nil { decode = JSONDecode } return lir.contents[idx].as(valuePtr, decode) }
go
{ "resource": "" }
q9553
Exists
train
func (lir *LookupInResult) Exists(idx int) bool { return lir.contents[idx].exists() }
go
{ "resource": "" }
q9554
Exists
train
func (d *ExistsResult) Exists() bool { return d.keyState != gocbcore.KeyStateNotFound && d.keyState != gocbcore.KeyStateDeleted }
go
{ "resource": "" }
q9555
Facets
train
func (r SearchResults) Facets() (map[string]SearchResultFacet, error) { if !r.streamResult.Closed() { return nil, errors.New("result must be closed before accessing meta-data") } return r.facets, nil }
go
{ "resource": "" }
q9556
Took
train
func (r SearchResultsMetadata) Took() time.Duration { return time.Duration(r.took) / time.Nanosecond }
go
{ "resource": "" }
q9557
SearchQuery
train
func (c *Cluster) SearchQuery(q SearchQuery, opts *SearchQueryOptions) (*SearchResults, error) { if opts == nil { opts = &SearchQueryOptions{} } ctx := opts.Context if ctx == nil { ctx = context.Background() } var span opentracing.Span if opts.ParentSpanContext == nil { span = opentracing.GlobalTracer().StartSpan("ExecuteSearchQuery", opentracing.Tag{Key: "couchbase.service", Value: "fts"}) } else { span = opentracing.GlobalTracer().StartSpan("ExecuteSearchQuery", opentracing.Tag{Key: "couchbase.service", Value: "fts"}, opentracing.ChildOf(opts.ParentSpanContext)) } defer span.Finish() provider, err := c.getHTTPProvider() if err != nil { return nil, err } return c.searchQuery(ctx, span.Context(), q, opts, provider) }
go
{ "resource": "" }
q9558
Upsert
train
func (c *Collection) Upsert(key string, val interface{}, opts *UpsertOptions) (mutOut *MutationResult, errOut error) { if opts == nil { opts = &UpsertOptions{} } span := c.startKvOpTrace(opts.ParentSpanContext, "Upsert") defer span.Finish() ctx, cancel := c.context(opts.Context, opts.Timeout) if cancel != nil { defer cancel() } res, err := c.upsert(ctx, span.Context(), key, val, *opts) if err != nil { return nil, err } if opts.PersistTo == 0 && opts.ReplicateTo == 0 { return res, nil } return res, c.durability(durabilitySettings{ ctx: opts.Context, tracectx: span.Context(), key: key, cas: res.Cas(), mt: res.MutationToken(), replicaTo: opts.ReplicateTo, persistTo: opts.PersistTo, forDelete: false, scopeName: c.scopeName(), collectionName: c.name(), }) }
go
{ "resource": "" }
q9559
get
train
func (c *Collection) get(ctx context.Context, traceCtx opentracing.SpanContext, key string, opts *GetOptions) (docOut *GetResult, errOut error) { span := c.startKvOpTrace(traceCtx, "get") defer span.Finish() agent, err := c.getKvProvider() if err != nil { return nil, err } ctrl := c.newOpManager(ctx) err = ctrl.wait(agent.GetEx(gocbcore.GetOptions{ Key: []byte(key), TraceContext: traceCtx, CollectionName: c.name(), ScopeName: c.scopeName(), }, func(res *gocbcore.GetResult, err error) { if err != nil { errOut = maybeEnhanceErr(err, key) ctrl.resolve() return } if res != nil { doc := &GetResult{ Result: Result{ cas: Cas(res.Cas), }, contents: res.Value, flags: res.Flags, } docOut = doc } ctrl.resolve() })) if err != nil { errOut = err } return }
go
{ "resource": "" }
q9560
Exists
train
func (c *Collection) Exists(key string, opts *ExistsOptions) (docOut *ExistsResult, errOut error) { if opts == nil { opts = &ExistsOptions{} } span := c.startKvOpTrace(opts.ParentSpanContext, "Exists") defer span.Finish() ctx, cancel := c.context(opts.Context, opts.Timeout) if cancel != nil { defer cancel() } res, err := c.exists(ctx, span.Context(), key, *opts) if err != nil { return nil, err } return res, nil }
go
{ "resource": "" }
q9561
GetFromReplica
train
func (c *Collection) GetFromReplica(key string, replicaIdx int, opts *GetFromReplicaOptions) (docOut *GetResult, errOut error) { if opts == nil { opts = &GetFromReplicaOptions{} } span := c.startKvOpTrace(opts.ParentSpanContext, "GetFromReplica") defer span.Finish() ctx, cancel := c.context(opts.Context, opts.Timeout) if cancel != nil { defer cancel() } res, err := c.getFromReplica(ctx, span.Context(), key, replicaIdx, *opts) if err != nil { return nil, err } return res, nil }
go
{ "resource": "" }
q9562
GetAndTouch
train
func (c *Collection) GetAndTouch(key string, expiration uint32, opts *GetAndTouchOptions) (docOut *GetResult, errOut error) { if opts == nil { opts = &GetAndTouchOptions{} } span := c.startKvOpTrace(opts.ParentSpanContext, "GetAndTouch") defer span.Finish() ctx, cancel := c.context(opts.Context, opts.Timeout) if cancel != nil { defer cancel() } res, err := c.getAndTouch(ctx, span.Context(), key, expiration, *opts) if err != nil { return nil, err } return res, nil }
go
{ "resource": "" }
q9563
GetAndLock
train
func (c *Collection) GetAndLock(key string, expiration uint32, opts *GetAndLockOptions) (docOut *GetResult, errOut error) { if opts == nil { opts = &GetAndLockOptions{} } span := c.startKvOpTrace(opts.ParentSpanContext, "GetAndLock") defer span.Finish() ctx, cancel := c.context(opts.Context, opts.Timeout) if cancel != nil { defer cancel() } res, err := c.getAndLock(ctx, span.Context(), key, expiration, *opts) if err != nil { return nil, err } return res, nil }
go
{ "resource": "" }
q9564
Unlock
train
func (c *Collection) Unlock(key string, opts *UnlockOptions) (mutOut *MutationResult, errOut error) { if opts == nil { opts = &UnlockOptions{} } span := c.startKvOpTrace(opts.ParentSpanContext, "Unlock") defer span.Finish() ctx, cancel := c.context(opts.Context, opts.Timeout) if cancel != nil { defer cancel() } res, err := c.unlock(ctx, span.Context(), key, *opts) if err != nil { return nil, err } return res, nil }
go
{ "resource": "" }
q9565
Touch
train
func (c *Collection) Touch(key string, expiration uint32, opts *TouchOptions) (mutOut *MutationResult, errOut error) { if opts == nil { opts = &TouchOptions{} } span := c.startKvOpTrace(opts.ParentSpanContext, "Touch") defer span.Finish() ctx, cancel := c.context(opts.Context, opts.Timeout) if cancel != nil { defer cancel() } res, err := c.touch(ctx, span.Context(), key, expiration, *opts) if err != nil { return nil, err } return res, nil }
go
{ "resource": "" }
q9566
GetFull
train
func (spec LookupInSpec) GetFull(opts *LookupInSpecGetFullOptions) LookupInOp { op := gocbcore.SubDocOp{ Op: gocbcore.SubDocOpGetDoc, Flags: gocbcore.SubdocFlag(SubdocFlagNone), } return LookupInOp{op: op} }
go
{ "resource": "" }
q9567
Count
train
func (spec LookupInSpec) Count(path string, opts *LookupInSpecCountOptions) LookupInOp { if opts == nil { opts = &LookupInSpecCountOptions{} } var flags gocbcore.SubdocFlag if opts.IsXattr { flags |= gocbcore.SubdocFlag(SubdocFlagXattr) } op := gocbcore.SubDocOp{ Op: gocbcore.SubDocOpGetCount, Path: path, Flags: gocbcore.SubdocFlag(flags), } return LookupInOp{op: op} }
go
{ "resource": "" }
q9568
LookupIn
train
func (c *Collection) LookupIn(key string, ops []LookupInOp, opts *LookupInOptions) (docOut *LookupInResult, errOut error) { if opts == nil { opts = &LookupInOptions{} } // Only update ctx if necessary, this means that the original ctx.Done() signal will be triggered as expected ctx, cancel := c.context(opts.Context, opts.Timeout) if cancel != nil { defer cancel() } span := c.startKvOpTrace(opts.ParentSpanContext, "LookupIn") defer span.Finish() res, err := c.lookupIn(ctx, span.Context(), key, ops, *opts) if err != nil { return nil, err } return res, nil }
go
{ "resource": "" }
q9569
UpsertFull
train
func (spec MutateInSpec) UpsertFull(val interface{}, opts *MutateInSpecUpsertFullOptions) MutateInOp { if opts == nil { opts = &MutateInSpecUpsertFullOptions{} } encoder := opts.Encoder if opts.Encoder == nil { encoder = JSONEncode } marshaled, _, err := encoder(val) if err != nil { return MutateInOp{err: err} } op := gocbcore.SubDocOp{ Op: gocbcore.SubDocOpSetDoc, Flags: gocbcore.SubdocFlag(SubdocFlagNone), Value: marshaled, } return MutateInOp{op: op} }
go
{ "resource": "" }
q9570
Replace
train
func (spec MutateInSpec) Replace(path string, val interface{}, opts *MutateInSpecReplaceOptions) MutateInOp { if opts == nil { opts = &MutateInSpecReplaceOptions{} } var flags SubdocFlag if opts.IsXattr { flags |= SubdocFlagXattr } encoder := opts.Encoder if opts.Encoder == nil { encoder = JSONEncode } marshaled, _, err := encoder(val) if err != nil { return MutateInOp{err: err} } op := gocbcore.SubDocOp{ Op: gocbcore.SubDocOpReplace, Path: path, Flags: gocbcore.SubdocFlag(flags), Value: marshaled, } return MutateInOp{op: op} }
go
{ "resource": "" }
q9571
Remove
train
func (spec MutateInSpec) Remove(path string, opts *MutateInSpecRemoveOptions) MutateInOp { if opts == nil { opts = &MutateInSpecRemoveOptions{} } var flags SubdocFlag if opts.IsXattr { flags |= SubdocFlagXattr } op := gocbcore.SubDocOp{ Op: gocbcore.SubDocOpDelete, Path: path, Flags: gocbcore.SubdocFlag(flags), } return MutateInOp{op: op} }
go
{ "resource": "" }
q9572
RemoveFull
train
func (spec MutateInSpec) RemoveFull() (*MutateInOp, error) { op := gocbcore.SubDocOp{ Op: gocbcore.SubDocOpDeleteDoc, Flags: gocbcore.SubdocFlag(SubdocFlagNone), } return &MutateInOp{op: op}, nil }
go
{ "resource": "" }
q9573
ArrayAddUnique
train
func (spec MutateInSpec) ArrayAddUnique(path string, val interface{}, opts *MutateInSpecArrayAddUniqueOptions) MutateInOp { if opts == nil { opts = &MutateInSpecArrayAddUniqueOptions{} } var flags SubdocFlag _, ok := val.(MutationMacro) if ok { flags |= SubdocFlagUseMacros opts.IsXattr = true } if opts.CreatePath { flags |= SubdocFlagCreatePath } if opts.IsXattr { flags |= SubdocFlagXattr } encoder := opts.Encoder if opts.Encoder == nil { encoder = JSONEncode } marshaled, _, err := encoder(val) if err != nil { return MutateInOp{err: err} } op := gocbcore.SubDocOp{ Op: gocbcore.SubDocOpArrayAddUnique, Path: path, Flags: gocbcore.SubdocFlag(flags), Value: marshaled, } return MutateInOp{op: op} }
go
{ "resource": "" }
q9574
Decrement
train
func (spec MutateInSpec) Decrement(path string, delta int64, opts *MutateInSpecCounterOptions) MutateInOp { if opts == nil { opts = &MutateInSpecCounterOptions{} } var flags SubdocFlag if opts.CreatePath { flags |= SubdocFlagCreatePath } if opts.IsXattr { flags |= SubdocFlagXattr } encoder := opts.Encoder if opts.Encoder == nil { encoder = JSONEncode } marshaled, _, err := encoder(-delta) if err != nil { return MutateInOp{err: err} } op := gocbcore.SubDocOp{ Op: gocbcore.SubDocOpCounter, Path: path, Flags: gocbcore.SubdocFlag(flags), Value: marshaled, } return MutateInOp{op: op} }
go
{ "resource": "" }
q9575
MutateIn
train
func (c *Collection) MutateIn(key string, ops []MutateInOp, opts *MutateInOptions) (mutOut *MutateInResult, errOut error) { if opts == nil { opts = &MutateInOptions{} } span := c.startKvOpTrace(opts.ParentSpanContext, "MutateIn") defer span.Finish() // Only update ctx if necessary, this means that the original ctx.Done() signal will be triggered as expected ctx, cancel := c.context(opts.Context, opts.Timeout) if cancel != nil { defer cancel() } res, err := c.mutate(ctx, span.Context(), key, ops, *opts) if err != nil { return nil, err } if opts.PersistTo == 0 && opts.ReplicateTo == 0 { return res, nil } return res, c.durability(durabilitySettings{ ctx: opts.Context, tracectx: span.Context(), key: key, cas: res.Cas(), mt: res.MutationToken(), replicaTo: opts.ReplicateTo, persistTo: opts.PersistTo, forDelete: false, scopeName: c.scopeName(), collectionName: c.name(), }) }
go
{ "resource": "" }
q9576
Append
train
func (c *CollectionBinary) Append(key string, val []byte, opts *AppendOptions) (mutOut *MutationResult, errOut error) { if opts == nil { opts = &AppendOptions{} } span := c.startKvOpTrace(opts.ParentSpanContext, "BinaryAppend") defer span.Finish() // Only update ctx if necessary, this means that the original ctx.Done() signal will be triggered as expected ctx, cancel := c.context(opts.Context, opts.Timeout) if cancel != nil { defer cancel() } res, err := c.append(ctx, span.Context(), key, val, *opts) if err != nil { return nil, err } return res, nil }
go
{ "resource": "" }
q9577
Prepend
train
func (c *CollectionBinary) Prepend(key string, val []byte, opts *PrependOptions) (mutOut *MutationResult, errOut error) { if opts == nil { opts = &PrependOptions{} } span := c.startKvOpTrace(opts.ParentSpanContext, "BinaryPrepend") defer span.Finish() // Only update ctx if necessary, this means that the original ctx.Done() signal will be triggered as expected ctx, cancel := c.context(opts.Context, opts.Timeout) if cancel != nil { defer cancel() } res, err := c.prepend(ctx, span.Context(), key, val, *opts) if err != nil { return nil, err } return res, nil }
go
{ "resource": "" }
q9578
Decrement
train
func (c *CollectionBinary) Decrement(key string, opts *CounterOptions) (countOut *CounterResult, errOut error) { if opts == nil { opts = &CounterOptions{} } span := c.startKvOpTrace(opts.ParentSpanContext, "Decrement") defer span.Finish() // Only update ctx if necessary, this means that the original ctx.Done() signal will be triggered as expected ctx, cancel := c.context(opts.Context, opts.Timeout) if cancel != nil { defer cancel() } res, err := c.decrement(ctx, span.Context(), key, *opts) if err != nil { return nil, err } return res, nil }
go
{ "resource": "" }
q9579
ViewQuery
train
func (b *Bucket) ViewQuery(designDoc string, viewName string, opts *ViewOptions) (*ViewResults, error) { if opts == nil { opts = &ViewOptions{} } ctx := opts.Context if ctx == nil { ctx = context.Background() } var span opentracing.Span if opts.ParentSpanContext == nil { span = opentracing.GlobalTracer().StartSpan("ExecuteViewQuery", opentracing.Tag{Key: "couchbase.service", Value: "views"}) } else { span = opentracing.GlobalTracer().StartSpan("ExecuteViewQuery", opentracing.Tag{Key: "couchbase.service", Value: "views"}, opentracing.ChildOf(opts.ParentSpanContext)) } defer span.Finish() cli := b.sb.getCachedClient() provider, err := cli.getHTTPProvider() if err != nil { return nil, err } designDoc = b.maybePrefixDevDocument(opts.Development, designDoc) urlValues, err := opts.toURLValues() if err != nil { return nil, errors.Wrap(err, "could not parse query options") } return b.executeViewQuery(ctx, span.Context(), "_view", designDoc, viewName, *urlValues, provider) }
go
{ "resource": "" }
q9580
DefaultCollection
train
func (b *Bucket) DefaultCollection(opts *CollectionOptions) *Collection { return b.defaultScope().DefaultCollection(opts) }
go
{ "resource": "" }
q9581
NewTermFacet
train
func NewTermFacet(field string, size int) *TermFacet { mq := &TermFacet{} mq.data.Field = field mq.data.Size = size return mq }
go
{ "resource": "" }
q9582
AddRange
train
func (f *NumericFacet) AddRange(name string, start, end float64) *NumericFacet { f.data.NumericRanges = append(f.data.NumericRanges, numericFacetRange{ Name: name, Start: start, End: end, }) return f }
go
{ "resource": "" }
q9583
NewNumericFacet
train
func NewNumericFacet(field string, size int) *NumericFacet { mq := &NumericFacet{} mq.data.Field = field mq.data.Size = size return mq }
go
{ "resource": "" }
q9584
AddRange
train
func (f *DateFacet) AddRange(name string, start, end string) *DateFacet { f.data.DateRanges = append(f.data.DateRanges, dateFacetRange{ Name: name, Start: start, End: end, }) return f }
go
{ "resource": "" }
q9585
NewDateFacet
train
func NewDateFacet(field string, size int) *DateFacet { mq := &DateFacet{} mq.data.Field = field mq.data.Size = size return mq }
go
{ "resource": "" }
q9586
startKvOpTrace
train
func (c *Collection) startKvOpTrace(parentSpanCtx opentracing.SpanContext, operationName string) opentracing.Span { var span opentracing.Span if parentSpanCtx == nil { span = opentracing.GlobalTracer().StartSpan(operationName, opentracing.Tag{Key: "couchbase.collection", Value: c.sb.CollectionName}, opentracing.Tag{Key: "couchbase.service", Value: "kv"}) } else { span = opentracing.GlobalTracer().StartSpan(operationName, opentracing.Tag{Key: "couchbase.collection", Value: c.sb.CollectionName}, opentracing.Tag{Key: "couchbase.service", Value: "kv"}, opentracing.ChildOf(parentSpanCtx)) } return span }
go
{ "resource": "" }
q9587
DefaultDecode
train
func DefaultDecode(bytes []byte, flags uint32, out interface{}) error { valueType, compression := gocbcore.DecodeCommonFlags(flags) // Make sure compression is disabled if compression != gocbcore.NoCompression { return clientError{"Unexpected value compression"} } // Normal types of decoding if valueType == gocbcore.BinaryType { switch typedOut := out.(type) { case *[]byte: *typedOut = bytes return nil case *interface{}: *typedOut = bytes return nil default: return clientError{"You must encode binary in a byte array or interface"} } } else if valueType == gocbcore.StringType { switch typedOut := out.(type) { case *string: *typedOut = string(bytes) return nil case *interface{}: *typedOut = string(bytes) return nil default: return clientError{"You must encode a string in a string or interface"} } } else if valueType == gocbcore.JsonType { err := json.Unmarshal(bytes, &out) if err != nil { return err } return nil } return clientError{"Unexpected flags value"} }
go
{ "resource": "" }
q9588
DefaultEncode
train
func DefaultEncode(value interface{}) ([]byte, uint32, error) { var bytes []byte var flags uint32 var err error switch typeValue := value.(type) { case []byte: bytes = typeValue flags = gocbcore.EncodeCommonFlags(gocbcore.BinaryType, gocbcore.NoCompression) case *[]byte: bytes = *typeValue flags = gocbcore.EncodeCommonFlags(gocbcore.BinaryType, gocbcore.NoCompression) case string: bytes = []byte(typeValue) flags = gocbcore.EncodeCommonFlags(gocbcore.StringType, gocbcore.NoCompression) case *string: bytes = []byte(*typeValue) flags = gocbcore.EncodeCommonFlags(gocbcore.StringType, gocbcore.NoCompression) case *interface{}: return DefaultEncode(*typeValue) default: bytes, err = json.Marshal(value) if err != nil { return nil, 0, err } flags = gocbcore.EncodeCommonFlags(gocbcore.JsonType, gocbcore.NoCompression) } // No compression supported currently return bytes, flags, nil }
go
{ "resource": "" }
q9589
JSONEncode
train
func JSONEncode(value interface{}) ([]byte, uint32, error) { var bytes []byte flags := gocbcore.EncodeCommonFlags(gocbcore.JsonType, gocbcore.NoCompression) var err error switch typeValue := value.(type) { case []byte: bytes = typeValue case *[]byte: bytes = *typeValue case *interface{}: return JSONEncode(*typeValue) default: bytes, err = json.Marshal(value) if err != nil { return nil, 0, err } } // No compression supported currently return bytes, flags, nil }
go
{ "resource": "" }
q9590
JSONDecode
train
func JSONDecode(bytes []byte, _ uint32, out interface{}) error { switch typedOut := out.(type) { case *[]byte: *typedOut = bytes return nil case *interface{}: *typedOut = bytes return nil default: err := json.Unmarshal(bytes, &out) if err != nil { return err } return nil } }
go
{ "resource": "" }
q9591
IsScopeMissingError
train
func IsScopeMissingError(err error) bool { cause := errors.Cause(err) if kvErr, ok := cause.(KeyValueError); ok && kvErr.KVError() { return kvErr.StatusCode() == int(gocbcore.StatusScopeUnknown) } return false }
go
{ "resource": "" }
q9592
IsCollectionMissingError
train
func IsCollectionMissingError(err error) bool { cause := errors.Cause(err) if kvErr, ok := cause.(KeyValueError); ok && kvErr.KVError() { return kvErr.StatusCode() == int(gocbcore.StatusCollectionUnknown) } return false }
go
{ "resource": "" }
q9593
IsKeyExistsError
train
func IsKeyExistsError(err error) bool { cause := errors.Cause(err) if kvErr, ok := cause.(KeyValueError); ok && kvErr.KVError() { return kvErr.StatusCode() == int(gocbcore.StatusKeyExists) } return false }
go
{ "resource": "" }
q9594
IsKeyNotFoundError
train
func IsKeyNotFoundError(err error) bool { cause := errors.Cause(err) if kvErr, ok := cause.(KeyValueError); ok && kvErr.KVError() { return kvErr.StatusCode() == int(gocbcore.StatusKeyNotFound) } return false }
go
{ "resource": "" }
q9595
IsTempFailError
train
func IsTempFailError(err error) bool { cause := errors.Cause(err) if kvErr, ok := cause.(KeyValueError); ok && kvErr.KVError() { return kvErr.StatusCode() == int(gocbcore.StatusTmpFail) } return false }
go
{ "resource": "" }
q9596
IsValueTooBigError
train
func IsValueTooBigError(err error) bool { cause := errors.Cause(err) if kvErr, ok := cause.(KeyValueError); ok && kvErr.KVError() { return kvErr.StatusCode() == int(gocbcore.StatusTooBig) } return false }
go
{ "resource": "" }
q9597
IsKeyLockedError
train
func IsKeyLockedError(err error) bool { cause := errors.Cause(err) if kvErr, ok := cause.(KeyValueError); ok && kvErr.KVError() { return kvErr.StatusCode() == int(gocbcore.StatusLocked) } return false }
go
{ "resource": "" }
q9598
IsPathExistsError
train
func IsPathExistsError(err error) bool { cause := errors.Cause(err) if kvErr, ok := cause.(KeyValueError); ok && kvErr.KVError() { return kvErr.StatusCode() == int(gocbcore.StatusSubDocPathExists) } return false }
go
{ "resource": "" }
q9599
IsInvalidRangeError
train
func IsInvalidRangeError(err error) bool { cause := errors.Cause(err) if kvErr, ok := cause.(KeyValueError); ok && kvErr.KVError() { return kvErr.StatusCode() == int(gocbcore.StatusRangeError) } return false }
go
{ "resource": "" }