mirror of https://github.com/dtm-labs/dtm.git
11 changed files with 171 additions and 85 deletions
@ -1,38 +1,21 @@ |
|||
package dtmsvr |
|||
|
|||
import ( |
|||
"bytes" |
|||
"io/ioutil" |
|||
"time" |
|||
|
|||
"github.com/gin-gonic/gin" |
|||
"github.com/sirupsen/logrus" |
|||
"github.com/yedf/dtm/common" |
|||
) |
|||
|
|||
func Main() { |
|||
logrus.Printf("start dtmsvr") |
|||
gin.SetMode(gin.ReleaseMode) |
|||
app := gin.Default() |
|||
app.Use(func(c *gin.Context) { |
|||
body := "" |
|||
if c.Request.Method == "POST" { |
|||
rb, err := c.GetRawData() |
|||
if err != nil { |
|||
logrus.Printf("GetRawData error: %s", err.Error()) |
|||
} else { |
|||
body = string(rb) |
|||
c.Request.Body = ioutil.NopCloser(bytes.NewBuffer(rb)) |
|||
} |
|||
} |
|||
began := time.Now() |
|||
logrus.Printf("begin %s %s query: %s body: %s", c.Request.Method, c.FullPath(), c.Request.URL.RawQuery, body) |
|||
c.Next() |
|||
logrus.Printf("used %d ms %s %s query: %s", time.Since(began).Milliseconds(), c.Request.Method, c.FullPath(), c.Request.URL.RawQuery) |
|||
StartConsumePreparedMsg(1) |
|||
StartConsumeCommitedMsg(1) |
|||
logrus.Printf("dtmsvr listen at: 8080") |
|||
go StartSvr() |
|||
} |
|||
|
|||
}) |
|||
func StartSvr() { |
|||
logrus.Printf("start dtmsvr") |
|||
app := common.GetGinApp() |
|||
AddRoute(app) |
|||
// StartConsumePreparedMsg(1)
|
|||
StartConsumeCommitedMsg(1) |
|||
logrus.Printf("dtmsvr listen at: 8080") |
|||
go app.Run() |
|||
app.Run() |
|||
} |
|||
|
|||
@ -1,25 +1,27 @@ |
|||
package examples |
|||
|
|||
import ( |
|||
"github.com/gin-gonic/gin" |
|||
"github.com/sirupsen/logrus" |
|||
"github.com/yedf/dtm/common" |
|||
) |
|||
|
|||
func Main() { |
|||
go StartSvr() |
|||
trans(&TransReq{ |
|||
Amount: 30, |
|||
TransInFailed: false, |
|||
TransOutFailed: true, |
|||
}) |
|||
} |
|||
|
|||
func StartSvr() { |
|||
logrus.Printf("examples starting") |
|||
gin.SetMode(gin.ReleaseMode) |
|||
app := gin.Default() |
|||
app := common.GetGinApp() |
|||
app.POST(BusiApi+"/TransIn", TransIn) |
|||
app.POST(BusiApi+"/TransInCompensate", TransInCompensate) |
|||
app.POST(BusiApi+"/TransOut", TransOut) |
|||
app.POST(BusiApi+"/TransOutCompensate", TransOutCompensate) |
|||
app.POST(BusiApi+"/TransQuery", TransQuery) |
|||
|
|||
go app.Run(":8081") |
|||
logrus.Printf("examples istening at %d", BusiPort) |
|||
trans(&TransReq{ |
|||
Amount: 30, |
|||
TransInFailed: false, |
|||
TransOutFailed: true, |
|||
}) |
|||
app.Run(":8081") |
|||
} |
|||
|
|||
Loading…
Reference in new issue