diff --git a/app/main.go b/app/main.go index 368139b..fad2d42 100644 --- a/app/main.go +++ b/app/main.go @@ -12,7 +12,8 @@ import ( type M = map[string]interface{} func main() { - if os.Args[1] == "quick_start" { + if len(os.Args) > 1 && (os.Args[1] == "quick_start" || os.Args[1] == "qs") { + dtmsvr.PopulateMysql() dtmsvr.Main() examples.StartMain() for { diff --git a/dtmsvr/cron.go b/dtmsvr/cron.go index 5214f46..10d5827 100644 --- a/dtmsvr/cron.go +++ b/dtmsvr/cron.go @@ -3,6 +3,7 @@ package dtmsvr import ( "math" "math/rand" + "runtime/debug" "time" "github.com/sirupsen/logrus" @@ -54,7 +55,7 @@ func lockOneTrans(expireIn time.Duration, status string) *TransGlobal { func handlePanic() { if err := recover(); err != nil { - logrus.Errorf("----panic %s handlered", err.(error).Error()) + logrus.Errorf("\x1b[31m\n----panic %s handlered\x1b[0m\n%s", err.(error).Error(), string(debug.Stack())) } } diff --git a/dtmsvr/trans.go b/dtmsvr/trans.go index 4eee811..7677896 100644 --- a/dtmsvr/trans.go +++ b/dtmsvr/trans.go @@ -26,7 +26,7 @@ type TransGlobal struct { } func (*TransGlobal) TableName() string { - return "trans_global" + return "dtm.trans_global" } type TransProcessor interface { @@ -73,7 +73,7 @@ type TransBranch struct { } func (*TransBranch) TableName() string { - return "trans_branch" + return "dtm.trans_branch" } func (t *TransBranch) changeStatus(db *common.DB, status string) *gorm.DB { diff --git a/examples/quick_start.go b/examples/quick_start.go index d0292b4..2fc40cc 100644 --- a/examples/quick_start.go +++ b/examples/quick_start.go @@ -10,12 +10,15 @@ import ( "github.com/yedf/dtm/dtmcli" ) +// 启动命令:go run app/main.go qs + // 事务参与者的服务地址 const qsBusiApi = "/api/busi_start" const qsBusiPort = 8082 var qsBusi = fmt.Sprintf("http://localhost:%d%s", qsBusiPort, qsBusiApi) +// 被app/main.go调用,启动服务并运行示例 func StartMain() { go qsStartSvr() qsFireRequest() @@ -23,9 +26,9 @@ func StartMain() { } func qsStartSvr() { - logrus.Printf("quick start examples starting") app := common.GetGinApp() qsAddRoute(app) + logrus.Printf("quick qs examples listening at %d", qsBusiPort) app.Run(fmt.Sprintf(":%d", qsBusiPort)) } @@ -55,5 +58,4 @@ func qsAddRoute(app *gin.Engine) { app.POST(qsBusiApi+"/TransOutCompensate", common.WrapHandler(func(c *gin.Context) (interface{}, error) { return M{"result": "SUCCESS"}, nil })) - logrus.Printf("quick qs examples listening at %d", qsBusiPort) }