You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

main.go 943 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. package main
  2. import (
  3. "net/http"
  4. "github.com/gin-gonic/gin"
  5. "github.com/seata/seata-go/pkg/client"
  6. "github.com/seata/seata-go/pkg/common/log"
  7. ginmiddleware "github.com/seata/seata-go/pkg/integration/gin"
  8. "github.com/seata/seata-go/pkg/rm/tcc"
  9. )
  10. func main() {
  11. client.Init()
  12. r := gin.Default()
  13. // NOTE: when use gin,must set ContextWithFallback true when gin version >= 1.8.1
  14. //r.ContextWithFallback = true
  15. r.Use(ginmiddleware.TransactionMiddleware())
  16. userProviderProxy, err := tcc.NewTCCServiceProxy(&RMService{})
  17. if err != nil {
  18. log.Errorf("get userProviderProxy tcc service proxy error, %v", err.Error())
  19. return
  20. }
  21. r.POST("/prepare", func(c *gin.Context) {
  22. if _, err := userProviderProxy.Prepare(c, ""); err != nil {
  23. c.JSON(http.StatusOK, "prepare failure")
  24. return
  25. }
  26. c.JSON(http.StatusOK, "prepare ok")
  27. })
  28. if err := r.Run(":8080"); err != nil {
  29. log.Fatalf("start tcc server fatal: %v", err)
  30. }
  31. }