add intro-xa

This commit is contained in:
yedongfu 2021-06-09 14:12:52 +08:00
parent 28b19209f5
commit 132f6308ea
3 changed files with 9 additions and 4 deletions

View File

@ -12,12 +12,17 @@ import (
type M = map[string]interface{}
func main() {
if len(os.Args) == 1 { // 默认情况下展示saga例子
if len(os.Args) == 1 || os.Args[1] == "saga" { // 默认情况下展示saga例子
dtmsvr.PopulateMysql()
go dtmsvr.Main()
go examples.SagaStartSvr()
time.Sleep(100 * time.Millisecond)
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
go dtmsvr.StartSvr()
} else if os.Args[1] == "all" { // 运行所有示例

View File

@ -21,7 +21,7 @@ func RunSqlScript(mysql map[string]string, script string) {
sqls := strings.Split(string(content), ";")
for _, sql := range sqls {
s := strings.TrimSpace(sql)
if strings.Contains(strings.ToLower(s), "drop1") || s == "" {
if s == "" {
continue
}
logrus.Printf("executing: '%s'", s)

View File

@ -81,7 +81,7 @@ func xaTransIn(c *gin.Context) (interface{}, error) {
return fmt.Errorf("tranIn failed")
}
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
})
e2p(err)
@ -95,7 +95,7 @@ func xaTransOut(c *gin.Context) (interface{}, error) {
return fmt.Errorf("tranOut failed")
}
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
})
e2p(err)