config name change to DB
This commit is contained in:
parent
998daf5f8c
commit
bc4c0a8274
@ -21,7 +21,7 @@ func wait() {
|
|||||||
func main() {
|
func main() {
|
||||||
onlyServer := len(os.Args) > 1 && os.Args[1] == "dtmsvr"
|
onlyServer := len(os.Args) > 1 && os.Args[1] == "dtmsvr"
|
||||||
if !onlyServer { // 实际线上运行,只启动dtmsvr,不准备table相关的数据
|
if !onlyServer { // 实际线上运行,只启动dtmsvr,不准备table相关的数据
|
||||||
dtmsvr.PopulateMysql(true)
|
dtmsvr.PopulateDB(true)
|
||||||
}
|
}
|
||||||
dtmsvr.StartSvr() // 启动dtmsvr的api服务
|
dtmsvr.StartSvr() // 启动dtmsvr的api服务
|
||||||
go dtmsvr.CronExpiredTrans(-1) // 启动dtmsvr的定时过期查询
|
go dtmsvr.CronExpiredTrans(-1) // 启动dtmsvr的定时过期查询
|
||||||
@ -38,7 +38,7 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 下面是各类的例子
|
// 下面是各类的例子
|
||||||
examples.PopulateMysql(true)
|
examples.PopulateDB(true)
|
||||||
app := examples.BaseAppStartup()
|
app := examples.BaseAppStartup()
|
||||||
if os.Args[1] == "xa" { // 启动xa示例
|
if os.Args[1] == "xa" { // 启动xa示例
|
||||||
examples.XaSetup(app)
|
examples.XaSetup(app)
|
||||||
|
|||||||
@ -7,18 +7,18 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type testConfig struct {
|
type testConfig struct {
|
||||||
Mysql map[string]string `yaml:"Mysql"`
|
DB map[string]string `yaml:"DB"`
|
||||||
}
|
}
|
||||||
|
|
||||||
var config = testConfig{}
|
var config = testConfig{}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
InitConfig(GetProjectDir(), &config)
|
InitConfig(GetProjectDir(), &config)
|
||||||
config.Mysql["database"] = ""
|
config.DB["database"] = ""
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDb(t *testing.T) {
|
func TestDb(t *testing.T) {
|
||||||
db := DbGet(config.Mysql)
|
db := DbGet(config.DB)
|
||||||
err := func() (rerr error) {
|
err := func() (rerr error) {
|
||||||
defer P2E(&rerr)
|
defer P2E(&rerr)
|
||||||
dbr := db.NoMust().Exec("select a")
|
dbr := db.NoMust().Exec("select a")
|
||||||
@ -32,7 +32,7 @@ func TestDb(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestDbAlone(t *testing.T) {
|
func TestDbAlone(t *testing.T) {
|
||||||
db, con := DbAlone(config.Mysql)
|
db, con := DbAlone(config.DB)
|
||||||
dbr := db.Exec("select 1")
|
dbr := db.Exec("select 1")
|
||||||
assert.Equal(t, nil, dbr.Error)
|
assert.Equal(t, nil, dbr.Error)
|
||||||
con.Close()
|
con.Close()
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
Mysql:
|
DB:
|
||||||
|
driver: 'mysql'
|
||||||
host: 'localhost'
|
host: 'localhost'
|
||||||
user: 'root'
|
user: 'root'
|
||||||
password: ''
|
password: ''
|
||||||
|
|||||||
@ -4,7 +4,7 @@ import "github.com/yedf/dtm/common"
|
|||||||
|
|
||||||
type dtmsvrConfig struct {
|
type dtmsvrConfig struct {
|
||||||
TransCronInterval int64 `yaml:"TransCronInterval"` // 单位秒 当事务等待这个时间之后,还没有变化,则进行一轮处理,包括prepared中的任务和committed的任务
|
TransCronInterval int64 `yaml:"TransCronInterval"` // 单位秒 当事务等待这个时间之后,还没有变化,则进行一轮处理,包括prepared中的任务和committed的任务
|
||||||
Mysql map[string]string `yaml:"Mysql"`
|
DB map[string]string `yaml:"DB"`
|
||||||
}
|
}
|
||||||
|
|
||||||
var config = &dtmsvrConfig{
|
var config = &dtmsvrConfig{
|
||||||
@ -15,5 +15,5 @@ var dbName = "dtm"
|
|||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
common.InitConfig(common.GetProjectDir(), &config)
|
common.InitConfig(common.GetProjectDir(), &config)
|
||||||
config.Mysql["database"] = ""
|
config.DB["database"] = ""
|
||||||
}
|
}
|
||||||
|
|||||||
@ -20,9 +20,9 @@ var app *gin.Engine
|
|||||||
func TestMain(m *testing.M) {
|
func TestMain(m *testing.M) {
|
||||||
TransProcessedTestChan = make(chan string, 1)
|
TransProcessedTestChan = make(chan string, 1)
|
||||||
common.InitConfig(common.GetProjectDir(), &config)
|
common.InitConfig(common.GetProjectDir(), &config)
|
||||||
config.Mysql["database"] = dbName
|
config.DB["database"] = dbName
|
||||||
PopulateMysql(false)
|
PopulateDB(false)
|
||||||
examples.PopulateMysql(false)
|
examples.PopulateDB(false)
|
||||||
// 启动组件
|
// 启动组件
|
||||||
go StartSvr()
|
go StartSvr()
|
||||||
app = examples.BaseAppStartup()
|
app = examples.BaseAppStartup()
|
||||||
@ -130,7 +130,7 @@ func transQuery(t *testing.T, gid string) {
|
|||||||
|
|
||||||
func TestSqlDB(t *testing.T) {
|
func TestSqlDB(t *testing.T) {
|
||||||
asserts := assert.New(t)
|
asserts := assert.New(t)
|
||||||
db := common.DbGet(config.Mysql)
|
db := common.DbGet(config.DB)
|
||||||
transInfo := &dtmcli.TransInfo{
|
transInfo := &dtmcli.TransInfo{
|
||||||
TransType: "saga",
|
TransType: "saga",
|
||||||
Gid: "gid2",
|
Gid: "gid2",
|
||||||
|
|||||||
@ -21,7 +21,8 @@ func StartSvr() {
|
|||||||
time.Sleep(100 * time.Millisecond)
|
time.Sleep(100 * time.Millisecond)
|
||||||
}
|
}
|
||||||
|
|
||||||
// PopulateMysql setup mysql data
|
// PopulateDB setup mysql data
|
||||||
func PopulateMysql(skipDrop bool) {
|
func PopulateDB(skipDrop bool) {
|
||||||
examples.RunSQLScript(config.Mysql, common.GetCurrentCodeDir()+"/dtmsvr.sql", skipDrop)
|
file := fmt.Sprintf("%s/dtmsvr.%s.sql", common.GetCurrentCodeDir(), config.DB["driver"])
|
||||||
|
examples.RunSQLScript(config.DB, file, skipDrop)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -18,7 +18,7 @@ var p2e = common.P2E
|
|||||||
var e2p = common.E2P
|
var e2p = common.E2P
|
||||||
|
|
||||||
func dbGet() *common.DB {
|
func dbGet() *common.DB {
|
||||||
return common.DbGet(config.Mysql)
|
return common.DbGet(config.DB)
|
||||||
}
|
}
|
||||||
func writeTransLog(gid string, action string, status string, branch string, detail string) {
|
func writeTransLog(gid string, action string, status string, branch string, detail string) {
|
||||||
// if detail == "" {
|
// if detail == "" {
|
||||||
|
|||||||
@ -3,7 +3,7 @@ package examples
|
|||||||
import "github.com/yedf/dtm/common"
|
import "github.com/yedf/dtm/common"
|
||||||
|
|
||||||
type exampleConfig struct {
|
type exampleConfig struct {
|
||||||
Mysql map[string]string `yaml:"Mysql"`
|
DB map[string]string `yaml:"DB"`
|
||||||
}
|
}
|
||||||
|
|
||||||
var config = exampleConfig{}
|
var config = exampleConfig{}
|
||||||
@ -12,5 +12,5 @@ var dbName = "dtm_busi"
|
|||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
common.InitConfig(common.GetProjectDir(), &config)
|
common.InitConfig(common.GetProjectDir(), &config)
|
||||||
config.Mysql["database"] = dbName
|
config.DB["database"] = dbName
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
package examples
|
package examples
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
@ -28,7 +29,8 @@ func RunSQLScript(mysql map[string]string, script string, skipDrop bool) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// PopulateMysql populate example mysql data
|
// PopulateDB populate example mysql data
|
||||||
func PopulateMysql(skipDrop bool) {
|
func PopulateDB(skipDrop bool) {
|
||||||
RunSQLScript(config.Mysql, common.GetCurrentCodeDir()+"/examples.sql", skipDrop)
|
file := fmt.Sprintf("%s/examples.%s.sql", common.GetCurrentCodeDir(), config.DB["driver"])
|
||||||
|
RunSQLScript(config.DB, file, skipDrop)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -33,16 +33,16 @@ type UserAccountTrading struct {
|
|||||||
func (u *UserAccountTrading) TableName() string { return "user_account_trading" }
|
func (u *UserAccountTrading) TableName() string { return "user_account_trading" }
|
||||||
|
|
||||||
func dbGet() *common.DB {
|
func dbGet() *common.DB {
|
||||||
return common.DbGet(config.Mysql)
|
return common.DbGet(config.DB)
|
||||||
}
|
}
|
||||||
|
|
||||||
// XaSetup 挂载http的api,创建XaClient
|
// XaSetup 挂载http的api,创建XaClient
|
||||||
func XaSetup(app *gin.Engine) {
|
func XaSetup(app *gin.Engine) {
|
||||||
app.POST(BusiAPI+"/TransInXa", common.WrapHandler(xaTransIn))
|
app.POST(BusiAPI+"/TransInXa", common.WrapHandler(xaTransIn))
|
||||||
app.POST(BusiAPI+"/TransOutXa", common.WrapHandler(xaTransOut))
|
app.POST(BusiAPI+"/TransOutXa", common.WrapHandler(xaTransOut))
|
||||||
config.Mysql["database"] = "dtm_busi"
|
config.DB["database"] = "dtm_busi"
|
||||||
var err error
|
var err error
|
||||||
XaClient, err = dtmcli.NewXaClient(DtmServer, config.Mysql, app, Busi+"/xa")
|
XaClient, err = dtmcli.NewXaClient(DtmServer, config.DB, app, Busi+"/xa")
|
||||||
e2p(err)
|
e2p(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user