Beispiel #1
0
func GetWebHook() *whpkg.WebHook {
	w, err := webhook.NewWebHook(conf.Conf().WebHookConfPath)
	if err != nil {
		panic(err)
	}
	return w
}
Beispiel #2
0
package redis

import (
	"fmt"
	"github.com/ckeyer/dbc/conf"
	redis "gopkg.in/redis.v3"
)

var (
	redis_cli  *redis.Client
	redis_conf = conf.Conf().Redis
)

func GetRedis() (*redis.Client, error) {
	if redis_cli == nil {
		connstr := fmt.Sprintf("%s:%s", redis_conf.Host, redis_conf.Port)
		redis_cli = redis.NewClient(&redis.Options{
			Addr:     connstr,
			Password: redis_conf.Password,
			DB:       0,
		})
		_, err := redis_cli.Ping().Result()
		if err != nil {
			return nil, err
		}
	}
	return redis_cli, nil
}
Beispiel #3
0
package mongo

import (
	"fmt"
	"github.com/ckeyer/dbc/conf"
	mgo "gopkg.in/mgo.v2"
)

var (
	db       *mgo.Database
	mgo_conf = conf.Conf().Mongo
)

func GetMgoCollection(table string) *mgo.Collection {
	if db == nil {
		_, err := GetMongo()
		if err != nil {
			return nil
		}
	}
	return db.C(table)
}

func GetMongo() (*mgo.Database, error) {
	if db == nil {
		connstr := fmt.Sprintf("%s:%s/%s", mgo_conf.Host, mgo_conf.Port, mgo_conf.Instance)
		session, err := mgo.Dial(connstr)
		if err != nil {
			return nil, err
		}
		db = session.DB(mgo_conf.Instance)
Beispiel #4
0
package mysql

import (
	"database/sql"
	"fmt"
	"github.com/ckeyer/dbc/conf"
	_ "github.com/go-sql-driver/mysql"
)

var (
	mysql_conf = conf.Conf().Mysql
)

// var mysql *mysql.
func GetMysql() (*sql.DB, error) {
	connstr := fmt.Sprintf("%s:%s@tcp(%s:%s)/?charset=utf8",
		mysql_conf.User, mysql_conf.Password, mysql_conf.Host, mysql_conf.Port)
	db, err := sql.Open("mysql", connstr)
	if err != nil {
		return nil, err
	}
	return db, nil
}