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) Delete(conn *Conn, q *Query) (int32, error)
- func (executor *BaseCommandExecutor) ExecuteBuildInfo(conn *Conn, cmd *Command) (bson.Document, error)
- func (executor *BaseCommandExecutor) ExecuteCommand(conn *Conn, cmd *Command) (bson.Document, error)
- func (executor *BaseCommandExecutor) ExecuteGetLastError(conn *Conn, cmd *Command) (bson.Document, error)
- func (executor *BaseCommandExecutor) ExecuteIsMaster(conn *Conn, cmd *Command) (bson.Document, error)
- func (executor *BaseCommandExecutor) ExecuteSaslContinue(*Conn, *Command) (bson.Document, error)
- func (executor *BaseCommandExecutor) ExecuteSaslStart(conn *Conn, cmd *Command) (bson.Document, error)
- func (executor *BaseCommandExecutor) Find(conn *Conn, q *Query) ([]bson.Document, error)
- func (executor *BaseCommandExecutor) Insert(conn *Conn, q *Query) (int32, 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 Client
- func (client *Client) Close() error
- func (client *Client) Connect() error
- func (client *Client) GetCollection() string
- func (client *Client) GetDatabase() string
- func (client *Client) GetHost() string
- func (client *Client) GetPort() int
- func (client *Client) GetTimeout() time.Duration
- func (client *Client) InsertOne(doc interface{}) error
- 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)
- type Command
- type CommandExecutor
- type Config
- func (config *Config) Compressions() []string
- func (config *Config) IsAuthrizationEnabled() bool
- func (config *Config) IsMaster() bool
- func (config *Config) IsReadOnly() bool
- func (config *Config) LogicalSessionTimeoutMinutes() int32
- func (config *Config) MaxBsonObjectSize() int32
- func (config *Config) MaxMessageSizeBytes() int32
- func (config *Config) MaxWireVersion() int32
- func (config *Config) MaxWriteBatchSize() int32
- func (config *Config) MinWireVersion() int32
- func (config *Config) SetAuthrizationEnabled(authorized bool)
- func (config *Config) Version() string
- 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 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
- func (server *Server) ExecuteBuildInfo(conn *Conn, cmd *Command) (bson.Document, error)
- func (server *Server) ExecuteIsMaster(conn *Conn, cmd *Command) (bson.Document, error)
- func (server *Server) ExecuteSaslContinue(conn *Conn, cmd *Command) (bson.Document, error)
- func (server *Server) ExecuteSaslStart(conn *Conn, cmd *Command) (bson.Document, error)
- func (server *Server) GetAddress() string
- func (server *Server) GetPort() int
- func (server *Server) Restart() error
- func (server *Server) SetAddress(addr string)
- func (server *Server) SetMessageHandler(h OpMessageHandler)
- func (server *Server) SetMessageListener(l MessageListener)
- func (server *Server) SetPort(port int)
- func (server *Server) SetTracer(t tracer.Tracer)
- func (server *Server) Start() error
- func (server *Server) Stop() error
- type TLSConf
- func (config *TLSConf) IsTLSEnabled() bool
- func (config *TLSConf) SetClientAuthType(authType tls.ClientAuthType)
- func (config *TLSConf) SetRootCertFiles(files ...string) error
- func (config *TLSConf) SetRootCerts(certs ...[]byte)
- func (config *TLSConf) SetServerCert(cert []byte)
- func (config *TLSConf) SetServerCertFile(file string) error
- func (config *TLSConf) SetServerKey(key []byte)
- func (config *TLSConf) SetServerKeyFile(file string) error
- func (config *TLSConf) SetTLSConfig(tlsConfig *tls.Config)
- func (config *TLSConf) SetTLSEnabled(enabled bool)
- func (config *TLSConf) TLSConfig() (*tls.Config, error)
- 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.0"
)
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 { // ExecuteSaslStart handles SASLStart command. ExecuteSaslStart(*Conn, *Command) (bson.Document, error) // ExecuteSaslContinue handles SASLContinue command. ExecuteSaslContinue(*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) Delete ¶
func (executor *BaseCommandExecutor) Delete(conn *Conn, q *Query) (int32, error)
Delete hadles OP_DELETE and 'delete' query of OP_MSG.
func (*BaseCommandExecutor) ExecuteBuildInfo ¶
func (executor *BaseCommandExecutor) ExecuteBuildInfo(conn *Conn, cmd *Command) (bson.Document, error)
ExecuteBuildInfo returns statistics about the MongoDB build.
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) ExecuteGetLastError ¶
func (executor *BaseCommandExecutor) ExecuteGetLastError(conn *Conn, cmd *Command) (bson.Document, error)
ExecuteGetLastError returns statistics about the MongoDB build.
func (*BaseCommandExecutor) ExecuteIsMaster ¶
func (executor *BaseCommandExecutor) ExecuteIsMaster(conn *Conn, cmd *Command) (bson.Document, error)
ExecuteIsMaster returns information about this member’s role in the replica set, including whether it is the master.
func (*BaseCommandExecutor) ExecuteSaslContinue ¶ added in v1.2.0
ExecuteSaslContinue handles SASLContinue command.
func (*BaseCommandExecutor) ExecuteSaslStart ¶ added in v1.1.0
func (executor *BaseCommandExecutor) ExecuteSaslStart(conn *Conn, cmd *Command) (bson.Document, error)
ExecuteSaslStart handles SASLStart command.
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) 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 Client ¶
type Client struct { Host string Port int Database string Collection string Timeout time.Duration // contains filtered or unexported fields }
Client is an instance for Graphite protocols.
func (*Client) GetCollection ¶
GetCollection returns a destination collection.
func (*Client) GetDatabase ¶
GetDatabase returns a destination database.
func (*Client) GetTimeout ¶
GetTimeout return the timeout for the request.
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 struct {
// contains filtered or unexported fields
}
Config stores server configuration parammeters.
func NewDefaultConfig ¶
func NewDefaultConfig() *Config
NewDefaultConfig returns a default configuration instance.
func (*Config) Compressions ¶ added in v1.1.0
Compressions should return supported compress strings.
func (*Config) IsAuthrizationEnabled ¶ added in v1.1.4
IsAuthrizationEnabled returns true when the authorization is enabled.
func (*Config) IsMaster ¶
IsMaster should return true when the instance is running as master, otherwise false.
func (*Config) IsReadOnly ¶ added in v1.1.0
IsReadOnly should return true when the instance does not support write operations.
func (*Config) LogicalSessionTimeoutMinutes ¶ added in v1.1.0
LogicalSessionTimeoutMinutes should return a settion timeout value.
func (*Config) MaxBsonObjectSize ¶ added in v1.1.0
MaxBsonObjectSize should return a max limitation value of BSON object size.
func (*Config) MaxMessageSizeBytes ¶ added in v1.1.0
MaxMessageSizeBytes should return a max limitation value of message size.
func (*Config) MaxWireVersion ¶ added in v1.1.0
MaxWireVersion should return a max supported version.
func (*Config) MaxWriteBatchSize ¶ added in v1.1.0
MaxWriteBatchSize should return a max limitation value of write batch size.
func (*Config) MinWireVersion ¶ added in v1.1.0
MinWireVersion should return a min supported version.
func (*Config) SetAuthrizationEnabled ¶ added in v1.1.4
SetAuthrizationEnabled sets the authorization flag.
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 ¶
type DiagnosticCommandExecutor interface {
ExecuteBuildInfo(*Conn, *Command) (bson.Document, error)
}
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 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 ¶
type ReplicationCommandExecutor interface {
ExecuteIsMaster(*Conn, *Command) (bson.Document, error)
}
ReplicationCommandExecutor represents an executor interface for MongoDB replication commands.
type Server ¶
type Server struct { *Config *ConnManager *TLSConf tracer.Tracer Addr string Port int MessageHandler OpMessageHandler *BaseMessageHandler *BaseCommandExecutor *sasl.Server // contains filtered or unexported fields }
Server is an instance for MongoDB protocols.
func (*Server) ExecuteBuildInfo ¶
ExecuteBuildInfo returns statistics about the MongoDB build.
func (*Server) ExecuteIsMaster ¶
ExecuteIsMaster displays information about this member’s role in the replica set, including whether it is the master.
func (*Server) ExecuteSaslContinue ¶ added in v1.2.0
ExecuteSaslContinue handles SASLContinue command.
func (*Server) ExecuteSaslStart ¶ added in v1.2.0
ExecuteSaslStart handles SASLStart command.
func (*Server) GetAddress ¶ added in v1.0.0
GetAddress returns a listen address.
func (*Server) SetAddress ¶ added in v1.0.0
SetAddress sets a listen address.
func (*Server) SetMessageHandler ¶
func (server *Server) SetMessageHandler(h OpMessageHandler)
SetMessageHandler sets a message handler.
func (*Server) SetMessageListener ¶
func (server *Server) SetMessageListener(l MessageListener)
SetMessageListener sets a message listener.
type TLSConf ¶ added in v1.1.0
type TLSConf struct { ClientAuthType tls.ClientAuthType ServerCert []byte ServerKey []byte RootCerts [][]byte // contains filtered or unexported fields }
TLSConf represents a TLS configuration.
func NewTLSConf ¶ added in v1.1.0
func NewTLSConf() *TLSConf
NewTLSConf returns a new TLS configuration.
func (*TLSConf) IsTLSEnabled ¶ added in v1.1.0
IsEnabled returns true if the TLS is enabled.
func (*TLSConf) SetClientAuthType ¶ added in v1.1.0
func (config *TLSConf) SetClientAuthType(authType tls.ClientAuthType)
SetClientAuthType sets a client authentication type.
func (*TLSConf) SetRootCertFiles ¶ added in v1.1.0
SetRootCertFile sets a SSL root certificates.
func (*TLSConf) SetRootCerts ¶ added in v1.1.0
SetRootCerts sets a SSL root certificates.
func (*TLSConf) SetServerCert ¶ added in v1.1.0
SetServerCert sets a SSL server certificate.
func (*TLSConf) SetServerCertFile ¶ added in v1.1.0
SetServerCertFile sets a SSL server certificate file.
func (*TLSConf) SetServerKey ¶ added in v1.1.0
SetServerKey sets a SSL server key.
func (*TLSConf) SetServerKeyFile ¶ added in v1.1.0
SetServerKeyFile sets a SSL server key file.
func (*TLSConf) SetTLSConfig ¶ added in v1.1.0
SetTLSConfig sets a TLS configuration.
func (*TLSConf) SetTLSEnabled ¶ added in v1.1.0
SetTLSEnabled sets a TLS enabled flag.
type UserCommandExecutor ¶
type UserCommandExecutor interface { QueryCommandExecutor }
UserCommandExecutor represents an executor interface for MongoDB query commands.