rename and comments

This commit is contained in:
Lunny Xiao 2017-09-26 11:29:41 +08:00
parent 42c8f7d30d
commit 8353ce81e9
No known key found for this signature in database
GPG Key ID: C3B7C91B632F738A
2 changed files with 9 additions and 10 deletions

View File

@ -1,4 +1,4 @@
// Copyright 2015 The Xorm Authors. All rights reserved. // Copyright 2017 The Xorm Authors. All rights reserved.
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
@ -21,12 +21,12 @@ type EngineGroup struct {
weight []int weight []int
count int count int
s_count int s_count int
policy Policy policy GroupPolicy
p int p int
} }
func NewGroup(args1 interface{}, args2 interface{}, policies ...Policy) (*EngineGroup, error) { func NewGroup(args1 interface{}, args2 interface{}, policies ...GroupPolicy) (*EngineGroup, error) {
var policy Policy var policy GroupPolicy
if len(policies) > 0 { if len(policies) > 0 {
policy = policies[0] policy = policies[0]
} else { } else {
@ -47,7 +47,7 @@ func NewGroup(args1 interface{}, args2 interface{}, policies ...Policy) (*Engine
return nil, ErrParamsType return nil, ErrParamsType
} }
func newGroup1(driverName string, dataSourceNames string, policy Policy) (*EngineGroup, error) { func newGroup1(driverName string, dataSourceNames string, policy GroupPolicy) (*EngineGroup, error) {
conns := strings.Split(dataSourceNames, ";") conns := strings.Split(dataSourceNames, ";")
engines := make([]*Engine, len(conns)) engines := make([]*Engine, len(conns))
for i, _ := range conns { for i, _ := range conns {
@ -67,7 +67,7 @@ func newGroup1(driverName string, dataSourceNames string, policy Policy) (*Engin
}, nil }, nil
} }
func newGroup2(Master *Engine, Slaves []*Engine, policy Policy) (*EngineGroup, error) { func newGroup2(Master *Engine, Slaves []*Engine, policy GroupPolicy) (*EngineGroup, error) {
return &EngineGroup{ return &EngineGroup{
master: Master, master: Master,
slaves: Slaves, slaves: Slaves,
@ -77,7 +77,7 @@ func newGroup2(Master *Engine, Slaves []*Engine, policy Policy) (*EngineGroup, e
}, nil }, nil
} }
func (eg *EngineGroup) SetPolicy(policy Policy) *EngineGroup { func (eg *EngineGroup) SetPolicy(policy GroupPolicy) *EngineGroup {
eg.policy = policy eg.policy = policy
return eg return eg
} }

View File

@ -1,4 +1,4 @@
// Copyright 2015 The Xorm Authors. All rights reserved. // Copyright 2017 The Xorm Authors. All rights reserved.
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
@ -7,11 +7,10 @@ package xorm
import ( import (
"math/rand" "math/rand"
"sync" "sync"
"time" "time"
) )
type Policy interface { type GroupPolicy interface {
Slave(*EngineGroup) *Engine Slave(*EngineGroup) *Engine
} }