improve the NewEngineGroup interface

This commit is contained in:
Lunny Xiao 2017-09-28 17:30:00 +08:00
parent 71529c2e6f
commit 51acb3530a
No known key found for this signature in database
GPG Key ID: C3B7C91B632F738A
2 changed files with 3 additions and 5 deletions

View File

@ -5,8 +5,6 @@
package xorm
import (
"strings"
"github.com/go-xorm/core"
)
@ -27,9 +25,8 @@ func NewEngineGroup(args1 interface{}, args2 interface{}, policies ...GroupPolic
}
driverName, ok1 := args1.(string)
dataSourceNames, ok2 := args2.(string)
conns, ok2 := args2.([]string)
if ok1 && ok2 {
conns := strings.Split(dataSourceNames, ";")
engines := make([]*Engine, len(conns))
for i, conn := range conns {
engine, err := NewEngine(driverName, conn)

View File

@ -26,6 +26,7 @@ var (
mapType = flag.String("map_type", "snake", "indicate the name mapping")
cache = flag.Bool("cache", false, "if enable cache")
cluster = flag.Bool("cluster", false, "if this is a cluster")
splitter = flag.String("splitter", ";", "the splitter on connstr for cluster")
)
func createEngine(dbType, connStr string) error {
@ -36,7 +37,7 @@ func createEngine(dbType, connStr string) error {
testEngine, err = NewEngine(dbType, connStr)
} else {
testEngine, err = NewEngineGroup(dbType, connStr)
testEngine, err = NewEngineGroup(dbType, strings.Split(connStr, *splitter))
}
if err != nil {
return err