mirror of https://github.com/dtm-labs/dtm.git
csharpjavadistributed-transactionsdtmgogolangmicroservicenodejsphpdatabasesagaseatatcctransactiontransactionsxapythondistributed
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
63 lines
1.6 KiB
63 lines
1.6 KiB
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"strings"
|
|
|
|
"github.com/yedf/dtm/bench"
|
|
"github.com/yedf/dtm/common"
|
|
"github.com/yedf/dtm/dtmcli"
|
|
"github.com/yedf/dtm/dtmsvr"
|
|
"github.com/yedf/dtm/examples"
|
|
)
|
|
|
|
var usage = `dtm is a lightweight distributed transaction manager.
|
|
|
|
usage:
|
|
dtm [command]
|
|
|
|
Available commands:
|
|
dtmsvr run dtm as a server
|
|
dev create all needed table and run dtm as a server
|
|
bench start bench server
|
|
|
|
quick_start run quick start example (dtm will create needed table)
|
|
qs same as quick_start
|
|
`
|
|
|
|
func main() {
|
|
dtmcli.SetCurrentDBType(common.DtmConfig.DB["driver"])
|
|
if len(os.Args) == 1 {
|
|
fmt.Println(usage)
|
|
for name := range examples.Samples {
|
|
fmt.Printf("%4s%-18srun a sample includes %s\n", "", name, strings.ReplaceAll(name, "_", " "))
|
|
}
|
|
return
|
|
}
|
|
if os.Args[1] != "dtmsvr" { // 实际线上运行,只启动dtmsvr,不准备table相关的数据
|
|
dtmsvr.PopulateDB(true)
|
|
examples.PopulateDB(true)
|
|
}
|
|
dtmsvr.StartSvr() // 启动dtmsvr的api服务
|
|
go dtmsvr.CronExpiredTrans(-1) // 启动dtmsvr的定时过期查询
|
|
|
|
switch os.Args[1] {
|
|
case "quick_start", "qs":
|
|
// quick_start 比较独立,单独作为一个例子运行,方便新人上手
|
|
examples.QsStartSvr()
|
|
examples.QsFireRequest()
|
|
case "bench":
|
|
bench.StartSvr()
|
|
case "dev", "dtmsvr":
|
|
default:
|
|
// 下面是各类的例子
|
|
examples.GrpcStartup()
|
|
examples.BaseAppStartup()
|
|
|
|
sample := examples.Samples[os.Args[1]]
|
|
dtmcli.LogIfFatalf(sample == nil, "no sample name for %s", os.Args[1])
|
|
sample.Action()
|
|
}
|
|
select {}
|
|
}
|
|
|