func ConnectDB() (*xorm.Engine, error) {
	var err error
	if engine != nil {
		return engine, err
	}
	if testFlag {
		engine, err = xorm.NewEngine("mysql", "root:@/dots_test")
	} else {
		engine, err = xorm.NewEngine("mysql", getDateSourceName())
	}
	return engine, err
}
database connection create
package models
import (
	"database/sql"
	"fmt"
	_ "github.com/go-sql-driver/mysql"
	"github.com/go-xorm/xorm"
	_ "github.com/lib/pq"
	dots_config "github.com/nttdots/go-dots/dots_server/config"
	log "github.com/sirupsen/logrus"
)
var engine *xorm.Engine
var testFlag bool = false
var dataSourceName string = ""
func SetTestMode(flag bool) {
	testFlag = flag
}
func getDateSourceName() string {
	if dataSourceName != "" {
		return dataSourceName
	}
	config := dots_config.GetServerSystemConfig().Database
	dataSourceName = fmt.Sprintf("%s:%s@%s(%s:%d)/%s", config.Username, config.Password, config.Protocol,
		config.Host, config.Port, config.DatabaseName)
	log.WithField("dataSource", dataSourceName).Debug("target database")
	return dataSourceName
}