package mgo import ( "errors" "github.com/henrylee2cn/pholcus/common/pool" "github.com/henrylee2cn/pholcus/config" "github.com/henrylee2cn/pholcus/logs" mgo "gopkg.in/mgo.v2" ) type MgoSrc struct { *mgo.Session } var MgoPool = pool.NewPool(new(MgoSrc), config.MGO_OUTPUT.MaxConns) // 新建数据库连接 func (*MgoSrc) New() pool.Src { session, err := mgo.Dial(config.MGO_OUTPUT.Host) if err != nil { logs.Log.Error("%v", err) } return &MgoSrc{Session: session} } // 判断连接是否失效 func (self *MgoSrc) Expired() bool { if self.Session.Ping() != nil { return true } return false
package mysql import ( "database/sql" _ "github.com/go-sql-driver/mysql" "github.com/henrylee2cn/pholcus/common/pool" "github.com/henrylee2cn/pholcus/common/util" "github.com/henrylee2cn/pholcus/config" "strings" ) /************************ Mysql 输出 ***************************/ var MysqlPool = pool.NewPool(new(MysqlSrc), config.MYSQL_OUTPUT.MAX_CONNS) type MysqlSrc struct { *sql.DB } func (self *MysqlSrc) New() pool.Src { db, err := sql.Open("mysql", config.MYSQL_OUTPUT.USER+":"+config.MYSQL_OUTPUT.PASSWORD+"@tcp("+config.MYSQL_OUTPUT.HOST+")/"+config.MYSQL_OUTPUT.DB+"?charset=utf8") if err != nil { panic(err) } return &MysqlSrc{DB: db} } // 判断连接是否失效 func (self *MysqlSrc) Expired() bool { if self.DB.Ping() != nil { return true }
package mysql import ( "database/sql" _ "github.com/go-sql-driver/mysql" "github.com/henrylee2cn/pholcus/common/pool" "github.com/henrylee2cn/pholcus/common/util" "github.com/henrylee2cn/pholcus/config" "strings" ) /************************ Mysql 输出 ***************************/ var MysqlPool = pool.NewPool(new(MysqlFish), 1024) type MysqlFish struct { *sql.DB } func (self *MysqlFish) New() pool.Fish { db, err := sql.Open("mysql", config.MYSQL_OUTPUT.User+":"+config.MYSQL_OUTPUT.Password+"@tcp("+config.MYSQL_OUTPUT.Host+")/"+config.MYSQL_OUTPUT.DefaultDB+"?charset=utf8") if err != nil { panic(err) } return &MysqlFish{DB: db} } // 判断连接有效性 func (self *MysqlFish) Usable() bool { if self.DB.Ping() != nil { return false }
package mgo import ( "errors" "github.com/henrylee2cn/pholcus/common/pool" "github.com/henrylee2cn/pholcus/config" "github.com/henrylee2cn/pholcus/logs" mgo "gopkg.in/mgo.v2" ) type MgoSrc struct { *mgo.Session } var MgoPool = pool.NewPool(new(MgoSrc), config.MGO.MAX_CONNS, 10) // 新建数据库连接 func (*MgoSrc) New() pool.Src { session, err := mgo.Dial(config.MGO.CONN_STR) if err != nil { logs.Log.Error("MongoDB: %v", err) return nil } return &MgoSrc{Session: session} } // 判断连接是否失效 func (self *MgoSrc) Expired() bool { if self.Session == nil || self.Session.Ping() != nil { return true }
package collector import ( "github.com/henrylee2cn/pholcus/common/pool" "github.com/henrylee2cn/pholcus/config" "gopkg.in/mgo.v2" "log" // "gopkg.in/mgo.v2/bson" ) /************************ MongoDB 输出 ***************************/ var mgoPool = pool.NewPool(new(mgoFish), 1024) type mgoFish struct { *mgo.Session } func (self *mgoFish) New() pool.Fish { mgoSession, err := mgo.Dial(config.MGO_OUTPUT.Host) if err != nil { panic(err) } mgoSession.SetMode(mgo.Monotonic, true) return &mgoFish{Session: mgoSession} } // 判断连接有效性 func (self *mgoFish) Usable() bool { if self.Session.Ping() != nil { return false }
package mgo import ( "errors" "github.com/henrylee2cn/pholcus/common/pool" "github.com/henrylee2cn/pholcus/config" "github.com/henrylee2cn/pholcus/logs" mgo "gopkg.in/mgo.v2" ) type MgoSrc struct { *mgo.Session } var MgoPool = pool.NewPool(new(MgoSrc), config.MGO_OUTPUT.MAX_CONNS) // 新建数据库连接 func (*MgoSrc) New() pool.Src { session, err := mgo.Dial(config.MGO_OUTPUT.HOST) if err != nil { logs.Log.Error("%v", err) } return &MgoSrc{Session: session} } // 判断连接是否失效 func (self *MgoSrc) Expired() bool { if self.Session.Ping() != nil { return true } return false
package mysql import ( "database/sql" _ "github.com/go-sql-driver/mysql" "github.com/henrylee2cn/pholcus/common/pool" "github.com/henrylee2cn/pholcus/common/util" "github.com/henrylee2cn/pholcus/config" "strings" ) /************************ Mysql 输出 ***************************/ var MysqlPool = pool.NewPool(new(MysqlSrc), config.MYSQL_OUTPUT.MaxConns) type MysqlSrc struct { *sql.DB } func (self *MysqlSrc) New() pool.Src { db, err := sql.Open("mysql", config.MYSQL_OUTPUT.User+":"+config.MYSQL_OUTPUT.Password+"@tcp("+config.MYSQL_OUTPUT.Host+")/"+config.MYSQL_OUTPUT.DefaultDB+"?charset=utf8") if err != nil { panic(err) } return &MysqlSrc{DB: db} } // 判断连接是否失效 func (self *MysqlSrc) Expired() bool { if self.DB.Ping() != nil { return true }
package mysql import ( "database/sql" _ "github.com/go-sql-driver/mysql" "github.com/henrylee2cn/pholcus/common/pool" "github.com/henrylee2cn/pholcus/common/util" "github.com/henrylee2cn/pholcus/config" "github.com/henrylee2cn/pholcus/logs" "strings" ) /************************ Mysql 输出 ***************************/ var MysqlPool = pool.NewPool(new(MysqlSrc), config.MYSQL.MAX_CONNS, 10) type MysqlSrc struct { *sql.DB } func (self *MysqlSrc) New() pool.Src { db, err := sql.Open("mysql", config.MYSQL.CONN_STR+"/"+config.MYSQL.DB+"?charset=utf8") if err != nil { logs.Log.Error("Mysql:%v", err) return nil } return &MysqlSrc{DB: db} } // 判断连接是否失效 func (self *MysqlSrc) Expired() bool { if self.DB == nil || self.DB.Ping() != nil {
package collector import ( "database/sql" _ "github.com/go-sql-driver/mysql" "github.com/henrylee2cn/pholcus/common/pool" "github.com/henrylee2cn/pholcus/common/util" "github.com/henrylee2cn/pholcus/config" "strings" ) /************************ Mysql 输出 ***************************/ var mysqlPool = pool.NewPool(new(mysqlFish), 1024) type mysqlFish struct { *sql.DB } func (self *mysqlFish) New() pool.Fish { db, err := sql.Open("mysql", config.MYSQL_OUTPUT.User+":"+config.MYSQL_OUTPUT.Password+"@tcp("+config.MYSQL_OUTPUT.Host+")/"+config.MYSQL_OUTPUT.DefaultDB+"?charset=utf8") if err != nil { panic(err) } return &mysqlFish{DB: db} } // 判断连接有效性 func (self *mysqlFish) Usable() bool { if self.DB.Ping() != nil { return false }