improve the NewEngineGroup interface

This commit is contained in:
Lunny Xiao 2017-09-28 17:30:00 +08:00
parent 7378a2f1d0
commit e5e4d6078e
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 package xorm
import ( import (
"strings"
"github.com/go-xorm/core" "github.com/go-xorm/core"
) )
@ -27,9 +25,8 @@ func NewEngineGroup(args1 interface{}, args2 interface{}, policies ...GroupPolic
} }
driverName, ok1 := args1.(string) driverName, ok1 := args1.(string)
dataSourceNames, ok2 := args2.(string) conns, ok2 := args2.([]string)
if ok1 && ok2 { if ok1 && ok2 {
conns := strings.Split(dataSourceNames, ";")
engines := make([]*Engine, len(conns)) engines := make([]*Engine, len(conns))
for i, conn := range conns { for i, conn := range conns {
engine, err := NewEngine(driverName, conn) engine, err := NewEngine(driverName, conn)

View File

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