Documentation
¶
Index ¶
- Variables
- type BaseFieldInterface
- type BaseMgoManyModel
- func (b *BaseMgoManyModel) GetAllFieldTag(structs BaseFieldInterface) bson.M
- func (this *BaseMgoManyModel) GetBuilder() (MgoBuilderApi, error)
- func (b *BaseMgoManyModel) GetItemTag(structs BaseFieldInterface, key string) string
- func (b *BaseMgoManyModel) GetItemTagAliasTable(structs BaseFieldInterface, key string, AliasTable string) string
- func (b *BaseMgoManyModel) GetItemTagNotTable(structs BaseFieldInterface, key string) string
- func (this *BaseMgoManyModel) GetSession(s func(session *mgo.Session, db *mgo.Database) error) error
- func (this *BaseMgoManyModel) GetSessionOnly() (*mgo.Session, *mgo.Database, error)
- func (this *BaseMgoManyModel) MultiTrans(session *mgo.Session, db *mgo.Database, ops []txn.Op) error
- func (this *BaseMgoManyModel) MultiTransactions(session *mgo.Session, db *mgo.Database, ops []txn.Op, transTable string, ...) error
- func (b *BaseMgoManyModel) Paginator(page int, pageSize int, totalNum int) int
- func (this *BaseMgoManyModel) SetBuildName(builderName string)
- func (this *BaseMgoManyModel) ShardCollectionHashed(collectionName string, shareKey string, sessionParam *mgo.Session) error
- type MgoBuilderApi
- type MgoError
- type MgoPool
- func (this *MgoPool) Connection() error
- func (this *MgoPool) GetBuilder(builderName string) (MgoBuilderApi, error)
- func (this *MgoPool) GetSession(builderName string, s func(session *mgo.Session, db *mgo.Database) error) error
- func (this *MgoPool) GetSessionOnly(builderName string) (*mgo.Session, *mgo.Database, error)
- func (this *MgoPool) SetBuilders(builders ...MgoBuilderApi)
Constants ¶
This section is empty.
Variables ¶
var ( DEFAULT_SESSION_SIZE int32 = 5 DEFAULT_POOL_SIZE int32 = 10 )
var ( MGO_ERROR_BUILDER_EMPTY = errors.New("mgo builder empty") MGO_ERROR_BUILDER_NAME_EMPTY = errors.New("mgo builder name can not be empty") MGO_ERROR_BUILDER_NOT_EXISTS = errors.New("mgo builder not exists") MGO_ERROR_CONNECTION_ERROR = errors.New("mgo connection error") MGO_EXEC_CALLBACK_ERROR = errors.New("mgo session call back error") )
var ( DEFULA_LOG_DIR = "/Log" UTFALL_DATE = "2006-01-02" )
var MPool = NewMgoPool()
Functions ¶
This section is empty.
Types ¶
type BaseMgoManyModel ¶
type BaseMgoManyModel struct {
// contains filtered or unexported fields
}
func (*BaseMgoManyModel) GetAllFieldTag ¶
func (b *BaseMgoManyModel) GetAllFieldTag(structs BaseFieldInterface) bson.M
* 获取所有 tag
func (*BaseMgoManyModel) GetBuilder ¶
func (this *BaseMgoManyModel) GetBuilder() (MgoBuilderApi, error)
func (*BaseMgoManyModel) GetItemTag ¶
func (b *BaseMgoManyModel) GetItemTag(structs BaseFieldInterface, key string) string
* 获取指定tag
func (*BaseMgoManyModel) GetItemTagAliasTable ¶
func (b *BaseMgoManyModel) GetItemTagAliasTable(structs BaseFieldInterface, key string, AliasTable string) string
* 获取指定标签 并转为别名
func (*BaseMgoManyModel) GetItemTagNotTable ¶
func (b *BaseMgoManyModel) GetItemTagNotTable(structs BaseFieldInterface, key string) string
func (*BaseMgoManyModel) GetSession ¶
func (this *BaseMgoManyModel) GetSession(s func(session *mgo.Session, db *mgo.Database) error) error
func (*BaseMgoManyModel) GetSessionOnly ¶
func (this *BaseMgoManyModel) GetSessionOnly() (*mgo.Session, *mgo.Database, error)
* 只获取session但不设置回调 [注] 获取后需手动释放session, session.Close()
func (*BaseMgoManyModel) MultiTrans ¶
func (this *BaseMgoManyModel) MultiTrans(session *mgo.Session, db *mgo.Database, ops []txn.Op) error
* 简版多文档提交 [主要是以mgo _id 为主键关联] @param session *mgo.Session mgo session @param db *mgo.Database mgo db @param opts []txn.Op 多文档操作条件
func (*BaseMgoManyModel) MultiTransactions ¶
func (this *BaseMgoManyModel) MultiTransactions(session *mgo.Session, db *mgo.Database, ops []txn.Op, transTable string, id bson.ObjectId, info interface{}) error
* 多文档提交 @param session *mgo.Session mgo session @param db *mgo.Database mgo db @param opts []txn.Op 多文档操作条件 @param transTable string 类似事务记录表 @param id bson.ObjectId 更新的主键id @param info interface{}
func (*BaseMgoManyModel) Paginator ¶
func (b *BaseMgoManyModel) Paginator(page int, pageSize int, totalNum int) int
* @title 总页数计算 @param page int 当前页 @param pageSize int 每页显示 @param totalNum int 总记录数
func (*BaseMgoManyModel) SetBuildName ¶
func (this *BaseMgoManyModel) SetBuildName(builderName string)
func (*BaseMgoManyModel) ShardCollectionHashed ¶
func (this *BaseMgoManyModel) ShardCollectionHashed(collectionName string, shareKey string, sessionParam *mgo.Session) error
* 集后分片 - hash @param collectionName string 集合名称 @param shareKey string 分键键 @param sessionParam *mgo.Session 如果为空则获取新的session
type MgoBuilderApi ¶
type MgoBuilderApi interface { //设置构建名称 SetBuilderName(builderName string) MgoBuilderApi GetBuilderName() string //设置服务地址 SetAddr(add string) MgoBuilderApi GetAddr() string //设置用户账号 SetUser(user string) MgoBuilderApi GetUser() string //设置密码 SetPwd(pwd string) MgoBuilderApi GetPwd() string //设置数据库 SetDataBase(dataBase string) MgoBuilderApi GetDataBase() string /** 设置session连接数 */ SetSessionSize(sessionSize int32) MgoBuilderApi GetSessionSize() int32 //设置session中每个连接池大小 SetPoolSize(poolSize int32) MgoBuilderApi GetPoolSize() int32 SetAuthDataBase(autDataBase string) MgoBuilderApi GetAuthDataBase() string //获取builder name hash GetHashName() string //是否为调试 SetIsDebug(isDebug bool) MgoBuilderApi GetIsDebug() bool //设置日志保存目录 SetLogDir(logDir string) MgoBuilderApi GetLogDir() string }
func NewMgoBuilder ¶
func NewMgoBuilder(builderName string, addr string, user string, pwd string, dataBase string) MgoBuilderApi
* 构建builder @param builderName string 构建名称(唯一) @param addr string 服务地址 @param user string 用户名 @param pwd string 密码 @param dataBase string 数据库
func NewMgoBuilderEm ¶
func NewMgoBuilderEm() MgoBuilderApi
type MgoError ¶
func (MgoError) RuntimeError ¶
func (this MgoError) RuntimeError()
type MgoPool ¶
type MgoPool struct {
// contains filtered or unexported fields
}
* mgo连接池
func NewMgoPool ¶
func NewMgoPool() *MgoPool
func (*MgoPool) GetBuilder ¶
func (this *MgoPool) GetBuilder(builderName string) (MgoBuilderApi, error)
func (*MgoPool) GetSession ¶
func (*MgoPool) GetSessionOnly ¶
func (*MgoPool) SetBuilders ¶
func (this *MgoPool) SetBuilders(builders ...MgoBuilderApi)