add intro-xa
This commit is contained in:
parent
28b19209f5
commit
132f6308ea
@ -12,12 +12,17 @@ import (
|
|||||||
type M = map[string]interface{}
|
type M = map[string]interface{}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
if len(os.Args) == 1 { // 默认情况下,展示saga例子
|
if len(os.Args) == 1 || os.Args[1] == "saga" { // 默认情况下,展示saga例子
|
||||||
dtmsvr.PopulateMysql()
|
dtmsvr.PopulateMysql()
|
||||||
go dtmsvr.Main()
|
go dtmsvr.Main()
|
||||||
go examples.SagaStartSvr()
|
go examples.SagaStartSvr()
|
||||||
time.Sleep(100 * time.Millisecond)
|
time.Sleep(100 * time.Millisecond)
|
||||||
examples.SagaFireRequest()
|
examples.SagaFireRequest()
|
||||||
|
} else if os.Args[1] == "xa" { // 启动xa示例
|
||||||
|
dtmsvr.PopulateMysql()
|
||||||
|
go dtmsvr.StartSvr()
|
||||||
|
examples.PopulateMysql()
|
||||||
|
examples.XaMain()
|
||||||
} else if os.Args[1] == "dtmsvr" { // 只启动dtmsvr
|
} else if os.Args[1] == "dtmsvr" { // 只启动dtmsvr
|
||||||
go dtmsvr.StartSvr()
|
go dtmsvr.StartSvr()
|
||||||
} else if os.Args[1] == "all" { // 运行所有示例
|
} else if os.Args[1] == "all" { // 运行所有示例
|
||||||
|
|||||||
@ -21,7 +21,7 @@ func RunSqlScript(mysql map[string]string, script string) {
|
|||||||
sqls := strings.Split(string(content), ";")
|
sqls := strings.Split(string(content), ";")
|
||||||
for _, sql := range sqls {
|
for _, sql := range sqls {
|
||||||
s := strings.TrimSpace(sql)
|
s := strings.TrimSpace(sql)
|
||||||
if strings.Contains(strings.ToLower(s), "drop1") || s == "" {
|
if s == "" {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
logrus.Printf("executing: '%s'", s)
|
logrus.Printf("executing: '%s'", s)
|
||||||
|
|||||||
@ -81,7 +81,7 @@ func xaTransIn(c *gin.Context) (interface{}, error) {
|
|||||||
return fmt.Errorf("tranIn failed")
|
return fmt.Errorf("tranIn failed")
|
||||||
}
|
}
|
||||||
dbr := db.Model(&UserAccount{}).Where("user_id = ?", c.Query("user_id")).
|
dbr := db.Model(&UserAccount{}).Where("user_id = ?", c.Query("user_id")).
|
||||||
Update("balance", gorm.Expr("balance - ?", req.Amount))
|
Update("balance", gorm.Expr("balance + ?", req.Amount))
|
||||||
return dbr.Error
|
return dbr.Error
|
||||||
})
|
})
|
||||||
e2p(err)
|
e2p(err)
|
||||||
@ -95,7 +95,7 @@ func xaTransOut(c *gin.Context) (interface{}, error) {
|
|||||||
return fmt.Errorf("tranOut failed")
|
return fmt.Errorf("tranOut failed")
|
||||||
}
|
}
|
||||||
dbr := db.Model(&UserAccount{}).Where("user_id = ?", c.Query("user_id")).
|
dbr := db.Model(&UserAccount{}).Where("user_id = ?", c.Query("user_id")).
|
||||||
Update("balance", gorm.Expr("balance + ?", req.Amount))
|
Update("balance", gorm.Expr("balance - ?", req.Amount))
|
||||||
return dbr.Error
|
return dbr.Error
|
||||||
})
|
})
|
||||||
e2p(err)
|
e2p(err)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user