Documentation ¶
Index ¶
- Constants
- Variables
- func NewErrorCommand(cmd *Command) error
- func NewNotSupported(q *Query) error
- func NewQueryError(q *Query) error
- type AuthCommandExecutor
- type BaseCommandExecutor
- func (executor *BaseCommandExecutor) BuildInfo(conn *Conn, cmd *Command) (bson.Document, error)
- func (executor *BaseCommandExecutor) Delete(conn *Conn, q *Query) (int32, error)
- func (executor *BaseCommandExecutor) ExecuteCommand(conn *Conn, cmd *Command) (bson.Document, error)
- func (executor *BaseCommandExecutor) Find(conn *Conn, q *Query) ([]bson.Document, error)
- func (executor *BaseCommandExecutor) GetLastError(conn *Conn, cmd *Command) (bson.Document, error)
- func (executor *BaseCommandExecutor) Hello(conn *Conn, cmd *Command) (bson.Document, error)
- func (executor *BaseCommandExecutor) Insert(conn *Conn, q *Query) (int32, error)
- func (executor *BaseCommandExecutor) SASLContinue(*Conn, *Command) (bson.Document, error)
- func (executor *BaseCommandExecutor) SASLStart(conn *Conn, cmd *Command) (bson.Document, error)
- func (executor *BaseCommandExecutor) SetAuthCommandExecutor(fn AuthCommandExecutor)
- func (executor *BaseCommandExecutor) SetDatabaseCommandExecutor(fn DatabaseCommandExecutor)
- func (executor *BaseCommandExecutor) SetUserCommandExecutor(fn UserCommandExecutor)
- func (executor *BaseCommandExecutor) Update(conn *Conn, q *Query) (int32, error)
- type BaseMessageHandler
- func (handler *BaseMessageHandler) OpDelete(conn *Conn, msg *OpDelete) (bson.Document, error)
- func (handler *BaseMessageHandler) OpGetMore(conn *Conn, msg *OpGetMore) (bson.Document, error)
- func (handler *BaseMessageHandler) OpInsert(conn *Conn, msg *OpInsert) (bson.Document, error)
- func (handler *BaseMessageHandler) OpKillCursors(conn *Conn, msg *OpKillCursors) (bson.Document, error)
- func (handler *BaseMessageHandler) OpMsg(conn *Conn, msg *OpMsg) (bson.Document, error)
- func (handler *BaseMessageHandler) OpQuery(conn *Conn, msg *OpQuery) (bson.Document, error)
- func (handler *BaseMessageHandler) OpUpdate(conn *Conn, msg *OpUpdate) (bson.Document, error)
- func (handler *BaseMessageHandler) SetCommandExecutor(fn CommandExecutor)
- func (handler *BaseMessageHandler) SetMessageExecutor(fn MessageExecutor)
- type CertConfig
- type Client
- func (client *Client) Close() error
- func (client *Client) Collection() string
- func (client *Client) Connect() error
- func (client *Client) Database() string
- func (client *Client) Host() string
- func (client *Client) InsertOne(doc interface{}) error
- func (client *Client) Port() int
- func (client *Client) SetCollection(col string)
- func (client *Client) SetDatabase(db string)
- func (client *Client) SetHost(host string)
- func (client *Client) SetPort(port int)
- func (client *Client) SetTimeout(d time.Duration)
- func (client *Client) Timeout() time.Duration
- type Command
- type CommandExecutor
- type Config
- type Conn
- func (conn *Conn) Close() error
- func (conn *Conn) IsAuthrized() bool
- func (conn *Conn) IsTLSConnection() bool
- func (conn *Conn) SASLContext() sasl.Context
- func (conn *Conn) SetAuthrized(authrized bool)
- func (conn *Conn) SetSASLContext(saslContext sasl.Context)
- func (conn *Conn) SetSpanContext(span tracer.Context)
- func (conn *Conn) SpanContext() tracer.Context
- func (conn *Conn) TLSConnectionState() (*tls.ConnectionState, bool)
- func (conn *Conn) Timestamp() time.Time
- func (conn *Conn) UUID() uuid.UUID
- type ConnManager
- func (mgr *ConnManager) AddConn(c *Conn)
- func (mgr *ConnManager) Close() error
- func (mgr *ConnManager) ConnByUUID(uuid uuid.UUID) (*Conn, bool)
- func (mgr *ConnManager) Conns() []*Conn
- func (mgr *ConnManager) RemoveConn(conn *Conn) error
- func (mgr *ConnManager) Start() error
- func (mgr *ConnManager) Stop() error
- type DatabaseCommandExecutor
- type DiagnosticCommandExecutor
- type Document
- type MessageExecutor
- type MessageListener
- type MessageResponse
- type OpDelete
- type OpFlag
- type OpGetMore
- type OpInsert
- type OpKillCursors
- type OpMessage
- type OpMessageHandler
- type OpMsg
- type OpQuery
- type OpReply
- type OpUpdate
- type Query
- type QueryCommandExecutor
- type ReplicationCommandExecutor
- type Server
- type TLSConfig
- type UserCommandExecutor
- type WriteOperationExecutor
Constants ¶
const ( // PackageName is the package name. PackageName = "go-mongo" // DefaultHost is the default host for MongoDB servers. DefaultHost string = "localhost" // DefaultPort is the default port for mongod and mongos. DefaultPort int = 27017 // DefaultTimeoutSecond is the default request timeout for MongoDB servers. DefaultTimeoutSecond = 5 )
const (
Version = "v1.2.2"
)
Variables ¶
var ErrCommand = errors.New("invalid command")
var ErrQuery = errors.New("query error")
var ErrQueryNotSupported = errors.New("query not supported")
Functions ¶
func NewErrorCommand ¶ added in v1.2.0
func NewNotSupported ¶ added in v0.9.1
func NewQueryError ¶ added in v0.9.1
Types ¶
type AuthCommandExecutor ¶ added in v1.1.0
type AuthCommandExecutor interface { // SASLSupportedMechs returns the supported SASL mechanisms. SASLSupportedMechs(*Conn, string) ([]sasl.SASLMechanism, error) // SASLStart handles SASLStart command. SASLStart(*Conn, *Command) (bson.Document, error) // SASLContinue handles SASLContinue command. SASLContinue(*Conn, *Command) (bson.Document, error) }
AuthCommandExecutor represents an executor interface for MongoDB authentication commands.
type BaseCommandExecutor ¶
type BaseCommandExecutor struct { UserCommandExecutor DatabaseCommandExecutor AuthCommandExecutor }
BaseCommandExecutor is a complete hander for CommandExecutor.
func NewBaseCommandExecutor ¶
func NewBaseCommandExecutor() *BaseCommandExecutor
NewBaseCommandExecutor returns a complete null executor for CommandExecutor.
func (*BaseCommandExecutor) BuildInfo ¶ added in v1.2.1
BuildInfo returns statistics about the MongoDB build.
func (*BaseCommandExecutor) Delete ¶
func (executor *BaseCommandExecutor) Delete(conn *Conn, q *Query) (int32, error)
Delete hadles OP_DELETE and 'delete' query of OP_MSG.
func (*BaseCommandExecutor) ExecuteCommand ¶
func (executor *BaseCommandExecutor) ExecuteCommand(conn *Conn, cmd *Command) (bson.Document, error)
ExecuteCommand handles query commands other than those explicitly specified above.
func (*BaseCommandExecutor) GetLastError ¶ added in v1.2.1
GetLastError returns statistics about the MongoDB build.
func (*BaseCommandExecutor) Hello ¶ added in v1.2.1
Hello returns information about this member’s role in the replica set, including whether it is the master.
func (*BaseCommandExecutor) Insert ¶
func (executor *BaseCommandExecutor) Insert(conn *Conn, q *Query) (int32, error)
Insert hadles OP_INSERT and 'insert' query of OP_MSG.
func (*BaseCommandExecutor) SASLContinue ¶ added in v1.2.1
SASLContinue handles SASLContinue command.
func (*BaseCommandExecutor) SetAuthCommandExecutor ¶ added in v1.2.0
func (executor *BaseCommandExecutor) SetAuthCommandExecutor(fn AuthCommandExecutor)
SetAuthCommandExecutor sets a command exector for auth operation commands.
func (*BaseCommandExecutor) SetDatabaseCommandExecutor ¶
func (executor *BaseCommandExecutor) SetDatabaseCommandExecutor(fn DatabaseCommandExecutor)
SetDatabaseCommandExecutor sets a command exector for database operation commands.
func (*BaseCommandExecutor) SetUserCommandExecutor ¶
func (executor *BaseCommandExecutor) SetUserCommandExecutor(fn UserCommandExecutor)
SetUserCommandExecutor sets a command exector for database operation commands.
type BaseMessageHandler ¶
type BaseMessageHandler struct { CommandExecutor MessageExecutor }
BaseMessageHandler is a complete hander for MessageHandler.
func NewBaseMessageHandler ¶
func NewBaseMessageHandler() *BaseMessageHandler
NewBaseMessageHandler returns a complete null handler for MessageHandler.
func (*BaseMessageHandler) OpKillCursors ¶
func (handler *BaseMessageHandler) OpKillCursors(conn *Conn, msg *OpKillCursors) (bson.Document, error)
OpKillCursors handles OP_KILL_CURSORS of MongoDB wire protocol.
func (*BaseMessageHandler) SetCommandExecutor ¶
func (handler *BaseMessageHandler) SetCommandExecutor(fn CommandExecutor)
SetCommandExecutor sets a exector for OP_QUERY of MongoDB wire protocol.
func (*BaseMessageHandler) SetMessageExecutor ¶
func (handler *BaseMessageHandler) SetMessageExecutor(fn MessageExecutor)
SetMessageExecutor sets a exector for OP_MSG of MongoDB wire protocol.
type CertConfig ¶ added in v1.2.2
type CertConfig interface { // SetClientAuthType sets a client authentication type. SetClientAuthType(authType tls.ClientAuthType) // SetServerKeyFile sets a SSL server key file. SetServerKeyFile(file string) error // SetServerCertFile sets a SSL server certificate file. SetServerCertFile(file string) error // SetRootCertFile sets a SSL root certificates. SetRootCertFiles(files ...string) error // SetServerKey sets a SSL server key. SetServerKey(key []byte) // SetServerCert sets a SSL server certificate. SetServerCert(cert []byte) // SetRootCerts sets a SSL root certificates. SetRootCerts(certs ...[]byte) // SetTLSConfig sets a TLS configuration. SetTLSConfig(tlsConfig *tls.Config) // TLSConfig returns a TLS configuration from the configuration. TLSConfig() (*tls.Config, error) }
CertConfig represents a TLS configuration interface.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is an instance for Graphite protocols.
func (*Client) Collection ¶
Collection returns a destination collection.
func (*Client) SetCollection ¶
SetCollection sets a destination collection.
func (*Client) SetDatabase ¶
SetDatabase sets a destination database.
func (*Client) SetTimeout ¶
SetTimeout sets a timeout for the request.
type CommandExecutor ¶
type CommandExecutor interface { // ExecuteCommand handles query commands other than those explicitly specified above. ExecuteCommand(*Conn, *Command) (bson.Document, error) }
CommandExecutor represents an interface for MongoDB database commands.
type Config ¶
type Config interface { TLSConfig message.Config // SetAuthrizationEnabled sets the authorization flag. SetAuthrizationEnabled(authorized bool) // IsAuthrizationEnabled returns true when the authorization is enabled. IsAuthrizationEnabled() bool // SetAddress sets a listen address. SetAddress(addr string) // Address returns a listen address. Address() string // SetPort sets a listen port. SetPort(port int) // Port returns a listent port. Port() int }
Config stores server configuration parammeters.
func NewDefaultConfig ¶
func NewDefaultConfig() Config
NewDefaultConfig returns a default configuration instance.
type Conn ¶ added in v0.9.2
Conn represents a connection of Wire protocol.
func (*Conn) IsAuthrized ¶ added in v1.1.0
IsAuthrized returns true if the connection is authrized.
func (*Conn) IsTLSConnection ¶ added in v1.1.3
IsTLSConnection return true if the connection is enabled TLS.
func (*Conn) SASLContext ¶ added in v1.2.0
SaslContext returns the SASL context of the connection.
func (*Conn) SetAuthrized ¶ added in v1.1.0
SetAuthrized sets the authrized flag to the connection.
func (*Conn) SetSASLContext ¶ added in v1.2.0
SetSaslContext sets the SASL context to the connection.
func (*Conn) SetSpanContext ¶ added in v1.0.1
SetSpanContext sets the span context to the connection.
func (*Conn) SpanContext ¶ added in v1.0.1
SpanContext returns the tracer span context of the connection.
func (*Conn) TLSConnectionState ¶ added in v1.1.3
func (conn *Conn) TLSConnectionState() (*tls.ConnectionState, bool)
TLSConnectionState returns the TLS connection state.
type ConnManager ¶ added in v1.1.4
type ConnManager struct {
// contains filtered or unexported fields
}
ConnManager represents a connection map.
func NewConnManager ¶ added in v1.1.4
func NewConnManager() *ConnManager
NewConnManager returns a connection map.
func (*ConnManager) AddConn ¶ added in v1.1.4
func (mgr *ConnManager) AddConn(c *Conn)
AddConn adds the specified connection.
func (*ConnManager) Close ¶ added in v1.1.4
func (mgr *ConnManager) Close() error
Close closes the connection manager.
func (*ConnManager) ConnByUUID ¶ added in v1.1.4
func (mgr *ConnManager) ConnByUUID(uuid uuid.UUID) (*Conn, bool)
ConnByUUID returns the connection with the specified UUID.
func (*ConnManager) Conns ¶ added in v1.1.4
func (mgr *ConnManager) Conns() []*Conn
Conns returns the included connections.
func (*ConnManager) RemoveConn ¶ added in v1.1.4
func (mgr *ConnManager) RemoveConn(conn *Conn) error
RemoveConn deletes the specified connection from the map.
func (*ConnManager) Start ¶ added in v1.1.4
func (mgr *ConnManager) Start() error
Start starts the connection manager.
func (*ConnManager) Stop ¶ added in v1.1.4
func (mgr *ConnManager) Stop() error
Stop closes all connections.
type DatabaseCommandExecutor ¶
type DatabaseCommandExecutor interface { ReplicationCommandExecutor DiagnosticCommandExecutor WriteOperationExecutor }
DatabaseCommandExecutor represents an executor interface for MongoDB operation commands.
type DiagnosticCommandExecutor ¶
DiagnosticCommandExecutor represents an executor interface for MongoDB diagnostic commands.
type MessageExecutor ¶
type MessageExecutor interface { QueryCommandExecutor }
MessageExecutor represents an executor interface for MongoDB message.
type MessageListener ¶
type MessageListener interface { protocol.MessageListener }
MessageListener represents a listener for MongoDB messages.
type MessageResponse ¶ added in v1.2.1
MessageResponse represents a message response.
type OpKillCursors ¶
type OpKillCursors = protocol.KillCursors
OpKillCursors (OP_KILL_CURSORS:2007) notifies database that the client has finished with the cursor.
type OpMessageHandler ¶
type OpMessageHandler interface { // Update handles OP_UPDATE of MongoDB wire protocol. OpUpdate(conn *Conn, q *OpUpdate) (bson.Document, error) // Insert handles OP_INSERT of MongoDB wire protocol. OpInsert(conn *Conn, q *OpInsert) (bson.Document, error) // Query handles OP_QUERY of MongoDB wire protocol. OpQuery(conn *Conn, q *OpQuery) (bson.Document, error) // GetMore handles GET_MORE of MongoDB wire protocol. OpGetMore(conn *Conn, q *OpGetMore) (bson.Document, error) // Delete handles OP_DELETE of MongoDB wire protocol. OpDelete(conn *Conn, q *OpDelete) (bson.Document, error) // KillCursors handles OP_KILL_CURSORS of MongoDB wire protocol. OpKillCursors(conn *Conn, q *OpKillCursors) (bson.Document, error) // Msg handles OP_MSG of MongoDB wire protocol. OpMsg(conn *Conn, q *OpMsg) (bson.Document, error) }
OpMessageHandler represents an interface for MongoDB query request.
type QueryCommandExecutor ¶ added in v0.9.2
type QueryCommandExecutor interface { // Insert hadles OP_INSERT and 'insert' query of OP_MSG. Insert(*Conn, *Query) (int32, error) // Update hadles OP_UPDATE and 'update' query of OP_MSG. Update(*Conn, *Query) (int32, error) // Find hadles 'find' query of OP_MSG. Find(*Conn, *Query) ([]bson.Document, error) // Delete hadles OP_DELETE and 'delete' query of OP_MSG. Delete(*Conn, *Query) (int32, error) }
QueryCommandExecutor represents an executor interface for MongoDB queries.
type ReplicationCommandExecutor ¶
ReplicationCommandExecutor represents an executor interface for MongoDB replication commands.
type Server ¶
type Server interface { Config auth.Manager // Config returns a server configuration. Config() Config // SetTracer sets a tracer. SetTracer(tracer.Tracer) // SetMessageListener sets a message listener. SetMessageListener(l MessageListener) // SetMessageHandler sets a message handler. SetMessageHandler(h OpMessageHandler) // SetUserCommandExecutor sets a command exector for database operation commands. SetUserCommandExecutor(fn UserCommandExecutor) // SetDatabaseCommandExecutor sets a command exector for database operation commands. SetDatabaseCommandExecutor(fn DatabaseCommandExecutor) // SetAuthCommandExecutor sets a command exector for auth operation commands. SetAuthCommandExecutor(fn AuthCommandExecutor) // Start starts a server. Start() error // Stop stops a server. Stop() error // Restart restarts a server. Restart() error }
Server represents a server interface.
type TLSConfig ¶ added in v1.2.2
type TLSConfig interface { CertConfig // SetTLSEnabled sets a TLS enabled flag. SetTLSEnabled(enabled bool) // IsEnabled returns true if the TLS is enabled. IsTLSEnabled() bool }
TLSConfig represents a TLS configuration interface.
type UserCommandExecutor ¶
type UserCommandExecutor interface { QueryCommandExecutor }
UserCommandExecutor represents an executor interface for MongoDB query commands.