newline battles continue

This commit is contained in:
bel
2020-01-19 20:41:30 +00:00
parent 98adb53caf
commit 573696774e
1456 changed files with 501133 additions and 6 deletions

View File

@@ -0,0 +1,74 @@
// Copyright (C) MongoDB, Inc. 2017-present.
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may
// not use this file except in compliance with the License. You may obtain
// a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
package internal
import (
"context"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/x/bsonx"
"go.mongodb.org/mongo-driver/x/network/wiremessage"
"errors"
"fmt"
)
// Implements the connection.Connection interface by reading and writing wire messages
// to a channel
type ChannelConn struct {
WriteErr error
Written chan wiremessage.WireMessage
ReadResp chan wiremessage.WireMessage
ReadErr chan error
}
func (c *ChannelConn) WriteWireMessage(ctx context.Context, wm wiremessage.WireMessage) error {
select {
case c.Written <- wm:
default:
c.WriteErr = errors.New("could not write wiremessage to written channel")
}
return c.WriteErr
}
func (c *ChannelConn) ReadWireMessage(ctx context.Context) (wiremessage.WireMessage, error) {
var wm wiremessage.WireMessage
var err error
select {
case wm = <-c.ReadResp:
case err = <-c.ReadErr:
case <-ctx.Done():
}
return wm, err
}
func (c *ChannelConn) Close() error {
return nil
}
func (c *ChannelConn) Expired() bool {
return false
}
func (c *ChannelConn) Alive() bool {
return true
}
func (c *ChannelConn) ID() string {
return "faked"
}
// Create a OP_REPLY wiremessage from a BSON document
func MakeReply(doc bsonx.Doc) (wiremessage.WireMessage, error) {
rdr, err := doc.MarshalBSON()
if err != nil {
return nil, errors.New(fmt.Sprintf("could not create document: %v", err))
}
return wiremessage.Reply{
NumberReturned: 1,
Documents: []bson.Raw{rdr},
}, nil
}

10
vendor/go.mongodb.org/mongo-driver/internal/const.go generated vendored Executable file
View File

@@ -0,0 +1,10 @@
// Copyright (C) MongoDB, Inc. 2017-present.
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may
// not use this file except in compliance with the License. You may obtain
// a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
package internal // import "go.mongodb.org/mongo-driver/internal"
// Version is the current version of the driver.
var Version = "local build"

119
vendor/go.mongodb.org/mongo-driver/internal/error.go generated vendored Executable file
View File

@@ -0,0 +1,119 @@
// Copyright (C) MongoDB, Inc. 2017-present.
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may
// not use this file except in compliance with the License. You may obtain
// a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
package internal
import (
"fmt"
)
// WrappedError represents an error that contains another error.
type WrappedError interface {
// Message gets the basic message of the error.
Message() string
// Inner gets the inner error if one exists.
Inner() error
}
// RolledUpErrorMessage gets a flattened error message.
func RolledUpErrorMessage(err error) string {
if wrappedErr, ok := err.(WrappedError); ok {
inner := wrappedErr.Inner()
if inner != nil {
return fmt.Sprintf("%s: %s", wrappedErr.Message(), RolledUpErrorMessage(inner))
}
return wrappedErr.Message()
}
return err.Error()
}
//UnwrapError attempts to unwrap the error down to its root cause.
func UnwrapError(err error) error {
switch tErr := err.(type) {
case WrappedError:
return UnwrapError(tErr.Inner())
case *multiError:
return UnwrapError(tErr.errors[0])
}
return err
}
// WrapError wraps an error with a message.
func WrapError(inner error, message string) error {
return &wrappedError{message, inner}
}
// WrapErrorf wraps an error with a message.
func WrapErrorf(inner error, format string, args ...interface{}) error {
return &wrappedError{fmt.Sprintf(format, args...), inner}
}
// MultiError combines multiple errors into a single error. If there are no errors,
// nil is returned. If there is 1 error, it is returned. Otherwise, they are combined.
func MultiError(errors ...error) error {
// remove nils from the error list
var nonNils []error
for _, e := range errors {
if e != nil {
nonNils = append(nonNils, e)
}
}
switch len(nonNils) {
case 0:
return nil
case 1:
return nonNils[0]
default:
return &multiError{
message: "multiple errors encountered",
errors: nonNils,
}
}
}
type multiError struct {
message string
errors []error
}
func (e *multiError) Message() string {
return e.message
}
func (e *multiError) Error() string {
result := e.message
for _, e := range e.errors {
result += fmt.Sprintf("\n %s", e)
}
return result
}
func (e *multiError) Errors() []error {
return e.errors
}
type wrappedError struct {
message string
inner error
}
func (e *wrappedError) Message() string {
return e.message
}
func (e *wrappedError) Error() string {
return RolledUpErrorMessage(e)
}
func (e *wrappedError) Inner() error {
return e.inner
}

54
vendor/go.mongodb.org/mongo-driver/internal/results.go generated vendored Executable file
View File

@@ -0,0 +1,54 @@
// Copyright (C) MongoDB, Inc. 2017-present.
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may
// not use this file except in compliance with the License. You may obtain
// a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
package internal
import (
"time"
"go.mongodb.org/mongo-driver/bson/primitive"
)
// IsMasterResult is the result of executing this
// ismaster command.
type IsMasterResult struct {
Arbiters []string `bson:"arbiters,omitempty"`
ArbiterOnly bool `bson:"arbiterOnly,omitempty"`
ElectionID primitive.ObjectID `bson:"electionId,omitempty"`
Hidden bool `bson:"hidden,omitempty"`
Hosts []string `bson:"hosts,omitempty"`
IsMaster bool `bson:"ismaster,omitempty"`
IsReplicaSet bool `bson:"isreplicaset,omitempty"`
LastWriteTimestamp time.Time `bson:"lastWriteDate,omitempty"`
MaxBSONObjectSize uint32 `bson:"maxBsonObjectSize,omitempty"`
MaxMessageSizeBytes uint32 `bson:"maxMessageSizeBytes,omitempty"`
MaxWriteBatchSize uint16 `bson:"maxWriteBatchSize,omitempty"`
Me string `bson:"me,omitempty"`
MaxWireVersion int32 `bson:"maxWireVersion,omitempty"`
MinWireVersion int32 `bson:"minWireVersion,omitempty"`
Msg string `bson:"msg,omitempty"`
OK int32 `bson:"ok"`
Passives []string `bson:"passives,omitempty"`
ReadOnly bool `bson:"readOnly,omitempty"`
Secondary bool `bson:"secondary,omitempty"`
SetName string `bson:"setName,omitempty"`
SetVersion uint32 `bson:"setVersion,omitempty"`
Tags map[string]string `bson:"tags,omitempty"`
}
// BuildInfoResult is the result of executing the
// buildInfo command.
type BuildInfoResult struct {
OK bool `bson:"ok"`
GitVersion string `bson:"gitVersion,omitempty"`
Version string `bson:"version,omitempty"`
VersionArray []uint8 `bson:"versionArray,omitempty"`
}
// GetLastErrorResult is the result of executing the
// getLastError command.
type GetLastErrorResult struct {
ConnectionID uint32 `bson:"connectionId"`
}

57
vendor/go.mongodb.org/mongo-driver/internal/semaphore.go generated vendored Executable file
View File

@@ -0,0 +1,57 @@
// Copyright (C) MongoDB, Inc. 2017-present.
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may
// not use this file except in compliance with the License. You may obtain
// a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
package internal
import (
"context"
"errors"
)
// NewSemaphore creates a new semaphore.
func NewSemaphore(slots uint64) *Semaphore {
ch := make(chan struct{}, slots)
for i := uint64(0); i < slots; i++ {
ch <- struct{}{}
}
return &Semaphore{
permits: ch,
}
}
// Semaphore is a synchronization primitive that controls access
// to a common resource.
type Semaphore struct {
permits chan struct{}
}
// Len gets the number of permits available.
func (s *Semaphore) Len() uint64 {
return uint64(len(s.permits))
}
// Wait waits until a resource is available or until the context
// is done.
func (s *Semaphore) Wait(ctx context.Context) error {
select {
case <-s.permits:
return nil
case <-ctx.Done():
return ctx.Err()
}
}
// Release releases a resource back into the pool.
func (s *Semaphore) Release() error {
select {
case s.permits <- struct{}{}:
default:
return errors.New("internal.Semaphore.Release: attempt to release more resources than are available")
}
return nil
}