busi

package
v0.0.0-...-431ae09 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 11, 2023 License: BSD-3-Clause Imports: 38 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// BusiAPI busi api prefix
	BusiAPI = "/api/busi"
	// BusiPort busi server port
	BusiPort = 8081
	// BusiGrpcPort busi server port
	BusiGrpcPort = 58081
)
View Source
const Mongo = "mongo"

Mongo 1

View Source
const Redis = "redis"

Redis 1

View Source
const TransInUID = 2

TransInUID 2

View Source
const TransOutUID = 1

TransOutUID 1

Variables

View Source
var Busi = fmt.Sprintf("http://localhost:%d%s", BusiPort, BusiAPI)

Busi busi service url prefix

View Source
var BusiConf = dtmcli.DBConf{
	Driver: "mysql",
	Host:   StoreHost,
	Port:   3306,
	User:   "root",
}

BusiConf 1

View Source
var BusiGrpc = fmt.Sprintf("localhost:%d", BusiGrpcPort)

BusiGrpc busi service grpc address

View Source
var BusiJrpcURL = fmt.Sprintf("http://localhost:%d/api/json-rpc?method=", BusiPort)

BusiJrpcURL url prefix for busi

View Source
var Busi_ServiceDesc = grpc.ServiceDesc{
	ServiceName: "busi.Busi",
	HandlerType: (*BusiServer)(nil),
	Methods: []grpc.MethodDesc{
		{
			MethodName: "TransIn",
			Handler:    _Busi_TransIn_Handler,
		},
		{
			MethodName: "TransOut",
			Handler:    _Busi_TransOut_Handler,
		},
		{
			MethodName: "TransInRevert",
			Handler:    _Busi_TransInRevert_Handler,
		},
		{
			MethodName: "TransOutRevert",
			Handler:    _Busi_TransOutRevert_Handler,
		},
		{
			MethodName: "TransInConfirm",
			Handler:    _Busi_TransInConfirm_Handler,
		},
		{
			MethodName: "TransOutConfirm",
			Handler:    _Busi_TransOutConfirm_Handler,
		},
		{
			MethodName: "XaNotify",
			Handler:    _Busi_XaNotify_Handler,
		},
		{
			MethodName: "TransInXa",
			Handler:    _Busi_TransInXa_Handler,
		},
		{
			MethodName: "TransOutXa",
			Handler:    _Busi_TransOutXa_Handler,
		},
		{
			MethodName: "TransInTcc",
			Handler:    _Busi_TransInTcc_Handler,
		},
		{
			MethodName: "TransOutTcc",
			Handler:    _Busi_TransOutTcc_Handler,
		},
		{
			MethodName: "TransInTccNested",
			Handler:    _Busi_TransInTccNested_Handler,
		},
		{
			MethodName: "TransInBSaga",
			Handler:    _Busi_TransInBSaga_Handler,
		},
		{
			MethodName: "TransOutBSaga",
			Handler:    _Busi_TransOutBSaga_Handler,
		},
		{
			MethodName: "TransInRevertBSaga",
			Handler:    _Busi_TransInRevertBSaga_Handler,
		},
		{
			MethodName: "TransOutRevertBSaga",
			Handler:    _Busi_TransOutRevertBSaga_Handler,
		},
		{
			MethodName: "TransOutHeaderYes",
			Handler:    _Busi_TransOutHeaderYes_Handler,
		},
		{
			MethodName: "TransOutHeaderNo",
			Handler:    _Busi_TransOutHeaderNo_Handler,
		},
		{
			MethodName: "TransInRedis",
			Handler:    _Busi_TransInRedis_Handler,
		},
		{
			MethodName: "TransOutRedis",
			Handler:    _Busi_TransOutRedis_Handler,
		},
		{
			MethodName: "TransInRevertRedis",
			Handler:    _Busi_TransInRevertRedis_Handler,
		},
		{
			MethodName: "TransOutRevertRedis",
			Handler:    _Busi_TransOutRevertRedis_Handler,
		},
		{
			MethodName: "QueryPrepared",
			Handler:    _Busi_QueryPrepared_Handler,
		},
		{
			MethodName: "QueryPreparedB",
			Handler:    _Busi_QueryPreparedB_Handler,
		},
		{
			MethodName: "QueryPreparedRedis",
			Handler:    _Busi_QueryPreparedRedis_Handler,
		},
	},
	Streams:  []grpc.StreamDesc{},
	Metadata: "test/busi/busi.proto",
}

Busi_ServiceDesc is the grpc.ServiceDesc for Busi service. It's only intended for direct use with grpc.RegisterService, and not to be introspected or modified (even as a copy)

View Source
var DtmClient dtmgpb.DtmClient

DtmClient grpc client for dtm

View Source
var File_test_busi_busi_proto protoreflect.FileDescriptor
View Source
var MainSwitch mainSwitchType

MainSwitch controls busi success or fail

View Source
var StoreHost = "localhost"

StoreHost examples will connect to dtm.pub; tests will connect to localhost

View Source
var WebHookResult gin.H

WebHookResult 1

Functions

func BaseAddRoute

func BaseAddRoute(app *gin.Engine)

BaseAddRoute add base route handler

func BaseAppStartup

func BaseAppStartup() *gin.Engine

BaseAppStartup base app startup

func GetBalanceByUID

func GetBalanceByUID(uid int, store string) int

GetBalanceByUID 1

func GetRedisAccountKey

func GetRedisAccountKey(uid int) string

GetRedisAccountKey return redis key for uid

func GrpcStartup

func GrpcStartup() *grpc.Server

GrpcStartup for grpc

func MongoGet

func MongoGet() *mongo.Client

MongoGet get mongo client

func MustBarrierFromGin

func MustBarrierFromGin(c *gin.Context) *dtmcli.BranchBarrier

MustBarrierFromGin 1

func MustBarrierFromGrpc

func MustBarrierFromGrpc(ctx context.Context) *dtmcli.BranchBarrier

MustBarrierFromGrpc 1

func PopulateDB

func PopulateDB(skipDrop bool)

PopulateDB populate example mysql data

func QsFireRequest

func QsFireRequest() string

QsFireRequest quick start: fire request

func QsMain

func QsMain()

QsMain will be call from dtm/qs

func QsStartSvr

func QsStartSvr()

QsStartSvr quick start: start server

func RedisGet

func RedisGet() *redis.Client

RedisGet 1

func RegisterBusiServer

func RegisterBusiServer(s grpc.ServiceRegistrar, srv BusiServer)

func ResetXaData

func ResetXaData()

ResetXaData will rollback all pending xa transaction

func RunGrpc

func RunGrpc(server *grpc.Server)

RunGrpc start to serve grpc

func RunHTTP

func RunHTTP(app *gin.Engine)

RunHTTP will run http server

func SagaAdjustBalance

func SagaAdjustBalance(db dtmcli.DB, uid int, amount int, result string) error

SagaAdjustBalance 1

func SagaMongoAdjustBalance

func SagaMongoAdjustBalance(ctx context.Context, mc *mongo.Client, uid int, amount int, result string) error

SagaMongoAdjustBalance 1

func SetGrpcHeaderForHeadersYes

func SetGrpcHeaderForHeadersYes(ctx context.Context, method string, req, reply interface{}, cc *grpc.ClientConn, invoker grpc.UnaryInvoker, opts ...grpc.CallOption) error

SetGrpcHeaderForHeadersYes interceptor to set head for HeadersYes

func SetHTTPHeaderForHeadersYes

func SetHTTPHeaderForHeadersYes(c *resty.Client, r *resty.Request) error

SetHTTPHeaderForHeadersYes interceptor to set head for HeadersYes

func SetMongoBothAccount

func SetMongoBothAccount(amountA int, amountB int)

SetMongoBothAccount 1

func SetRedisBothAccount

func SetRedisBothAccount(amountA int, ammountB int)

SetRedisBothAccount 1

func SetSleepCancelHandler

func SetSleepCancelHandler(handler SleepCancelHandler)

SetSleepCancelHandler 1

func SetupMongoBarrierAndBusi

func SetupMongoBarrierAndBusi()

SetupMongoBarrierAndBusi 1

func Startup

func Startup() (*gin.Engine, *grpc.Server)

Startup startup the busi's grpc and http service

func TccBarrierTransOutCancel

func TccBarrierTransOutCancel(c *gin.Context) interface{}

TccBarrierTransOutCancel will be use in test

Types

type AutoEmptyString

type AutoEmptyString struct {
	// contains filtered or unexported fields
}

AutoEmptyString auto reset to empty when used once

func (*AutoEmptyString) Fetch

func (s *AutoEmptyString) Fetch() string

Fetch fetch the stored value, then reset the value to empty

func (*AutoEmptyString) SetOnce

func (s *AutoEmptyString) SetOnce(v string)

SetOnce set a value once

type BusiClient

type BusiClient interface {
	TransIn(ctx context.Context, in *ReqGrpc, opts ...grpc.CallOption) (*emptypb.Empty, error)
	TransOut(ctx context.Context, in *ReqGrpc, opts ...grpc.CallOption) (*emptypb.Empty, error)
	TransInRevert(ctx context.Context, in *ReqGrpc, opts ...grpc.CallOption) (*emptypb.Empty, error)
	TransOutRevert(ctx context.Context, in *ReqGrpc, opts ...grpc.CallOption) (*emptypb.Empty, error)
	TransInConfirm(ctx context.Context, in *ReqGrpc, opts ...grpc.CallOption) (*emptypb.Empty, error)
	TransOutConfirm(ctx context.Context, in *ReqGrpc, opts ...grpc.CallOption) (*emptypb.Empty, error)
	XaNotify(ctx context.Context, in *emptypb.Empty, opts ...grpc.CallOption) (*emptypb.Empty, error)
	TransInXa(ctx context.Context, in *ReqGrpc, opts ...grpc.CallOption) (*emptypb.Empty, error)
	TransOutXa(ctx context.Context, in *ReqGrpc, opts ...grpc.CallOption) (*emptypb.Empty, error)
	TransInTcc(ctx context.Context, in *ReqGrpc, opts ...grpc.CallOption) (*emptypb.Empty, error)
	TransOutTcc(ctx context.Context, in *ReqGrpc, opts ...grpc.CallOption) (*emptypb.Empty, error)
	TransInTccNested(ctx context.Context, in *ReqGrpc, opts ...grpc.CallOption) (*emptypb.Empty, error)
	TransInBSaga(ctx context.Context, in *ReqGrpc, opts ...grpc.CallOption) (*emptypb.Empty, error)
	TransOutBSaga(ctx context.Context, in *ReqGrpc, opts ...grpc.CallOption) (*emptypb.Empty, error)
	TransInRevertBSaga(ctx context.Context, in *ReqGrpc, opts ...grpc.CallOption) (*emptypb.Empty, error)
	TransOutRevertBSaga(ctx context.Context, in *ReqGrpc, opts ...grpc.CallOption) (*emptypb.Empty, error)
	TransOutHeaderYes(ctx context.Context, in *ReqGrpc, opts ...grpc.CallOption) (*emptypb.Empty, error)
	TransOutHeaderNo(ctx context.Context, in *ReqGrpc, opts ...grpc.CallOption) (*emptypb.Empty, error)
	TransInRedis(ctx context.Context, in *ReqGrpc, opts ...grpc.CallOption) (*emptypb.Empty, error)
	TransOutRedis(ctx context.Context, in *ReqGrpc, opts ...grpc.CallOption) (*emptypb.Empty, error)
	TransInRevertRedis(ctx context.Context, in *ReqGrpc, opts ...grpc.CallOption) (*emptypb.Empty, error)
	TransOutRevertRedis(ctx context.Context, in *ReqGrpc, opts ...grpc.CallOption) (*emptypb.Empty, error)
	QueryPrepared(ctx context.Context, in *ReqGrpc, opts ...grpc.CallOption) (*BusiReply, error)
	QueryPreparedB(ctx context.Context, in *ReqGrpc, opts ...grpc.CallOption) (*emptypb.Empty, error)
	QueryPreparedRedis(ctx context.Context, in *ReqGrpc, opts ...grpc.CallOption) (*emptypb.Empty, error)
}

BusiClient is the client API for Busi service.

For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream.

var BusiCli BusiClient

BusiCli grpc client for busi

func NewBusiClient

func NewBusiClient(cc grpc.ClientConnInterface) BusiClient

type BusiReply

type BusiReply struct {
	Message string `protobuf:"bytes,1,opt,name=message,proto3" json:"message,omitempty"`
	// contains filtered or unexported fields
}

func (*BusiReply) Descriptor deprecated

func (*BusiReply) Descriptor() ([]byte, []int)

Deprecated: Use BusiReply.ProtoReflect.Descriptor instead.

func (*BusiReply) GetMessage

func (x *BusiReply) GetMessage() string

func (*BusiReply) ProtoMessage

func (*BusiReply) ProtoMessage()

func (*BusiReply) ProtoReflect

func (x *BusiReply) ProtoReflect() protoreflect.Message

func (*BusiReply) Reset

func (x *BusiReply) Reset()

func (*BusiReply) String

func (x *BusiReply) String() string

type BusiServer

type BusiServer interface {
	TransIn(context.Context, *ReqGrpc) (*emptypb.Empty, error)
	TransOut(context.Context, *ReqGrpc) (*emptypb.Empty, error)
	TransInRevert(context.Context, *ReqGrpc) (*emptypb.Empty, error)
	TransOutRevert(context.Context, *ReqGrpc) (*emptypb.Empty, error)
	TransInConfirm(context.Context, *ReqGrpc) (*emptypb.Empty, error)
	TransOutConfirm(context.Context, *ReqGrpc) (*emptypb.Empty, error)
	XaNotify(context.Context, *emptypb.Empty) (*emptypb.Empty, error)
	TransInXa(context.Context, *ReqGrpc) (*emptypb.Empty, error)
	TransOutXa(context.Context, *ReqGrpc) (*emptypb.Empty, error)
	TransInTcc(context.Context, *ReqGrpc) (*emptypb.Empty, error)
	TransOutTcc(context.Context, *ReqGrpc) (*emptypb.Empty, error)
	TransInTccNested(context.Context, *ReqGrpc) (*emptypb.Empty, error)
	TransInBSaga(context.Context, *ReqGrpc) (*emptypb.Empty, error)
	TransOutBSaga(context.Context, *ReqGrpc) (*emptypb.Empty, error)
	TransInRevertBSaga(context.Context, *ReqGrpc) (*emptypb.Empty, error)
	TransOutRevertBSaga(context.Context, *ReqGrpc) (*emptypb.Empty, error)
	TransOutHeaderYes(context.Context, *ReqGrpc) (*emptypb.Empty, error)
	TransOutHeaderNo(context.Context, *ReqGrpc) (*emptypb.Empty, error)
	TransInRedis(context.Context, *ReqGrpc) (*emptypb.Empty, error)
	TransOutRedis(context.Context, *ReqGrpc) (*emptypb.Empty, error)
	TransInRevertRedis(context.Context, *ReqGrpc) (*emptypb.Empty, error)
	TransOutRevertRedis(context.Context, *ReqGrpc) (*emptypb.Empty, error)
	QueryPrepared(context.Context, *ReqGrpc) (*BusiReply, error)
	QueryPreparedB(context.Context, *ReqGrpc) (*emptypb.Empty, error)
	QueryPreparedRedis(context.Context, *ReqGrpc) (*emptypb.Empty, error)
	// contains filtered or unexported methods
}

BusiServer is the server API for Busi service. All implementations must embed UnimplementedBusiServer for forward compatibility

type ReqGrpc

type ReqGrpc struct {
	Amount         int64  `protobuf:"varint,1,opt,name=Amount,proto3" json:"Amount,omitempty"`
	TransOutResult string `protobuf:"bytes,2,opt,name=TransOutResult,proto3" json:"TransOutResult,omitempty"`
	TransInResult  string `protobuf:"bytes,3,opt,name=TransInResult,proto3" json:"TransInResult,omitempty"`
	// contains filtered or unexported fields
}

DtmRequest request sent to dtm server

func GenReqGrpc

func GenReqGrpc(amount int, outFailed bool, inFailed bool) *ReqGrpc

GenReqGrpc 1

func (*ReqGrpc) Descriptor deprecated

func (*ReqGrpc) Descriptor() ([]byte, []int)

Deprecated: Use ReqGrpc.ProtoReflect.Descriptor instead.

func (*ReqGrpc) GetAmount

func (x *ReqGrpc) GetAmount() int64

func (*ReqGrpc) GetTransInResult

func (x *ReqGrpc) GetTransInResult() string

func (*ReqGrpc) GetTransOutResult

func (x *ReqGrpc) GetTransOutResult() string

func (*ReqGrpc) ProtoMessage

func (*ReqGrpc) ProtoMessage()

func (*ReqGrpc) ProtoReflect

func (x *ReqGrpc) ProtoReflect() protoreflect.Message

func (*ReqGrpc) Reset

func (x *ReqGrpc) Reset()

func (*ReqGrpc) String

func (x *ReqGrpc) String() string

type ReqHTTP

type ReqHTTP struct {
	Amount         int    `json:"amount"`
	TransInResult  string `json:"trans_in_result"`
	TransOutResult string `json:"trans_out_Result"`
	Store          string `json:"store"` // default mysql, value can be mysql|redis
}

ReqHTTP transaction request payload

func GenReqHTTP

func GenReqHTTP(amount int, outFailed bool, inFailed bool) *ReqHTTP

GenReqHTTP 1

func (*ReqHTTP) String

func (t *ReqHTTP) String() string

type SleepCancelHandler

type SleepCancelHandler func(c *gin.Context) interface{}

SleepCancelHandler 1

type UnimplementedBusiServer

type UnimplementedBusiServer struct {
}

UnimplementedBusiServer must be embedded to have forward compatible implementations.

func (UnimplementedBusiServer) QueryPrepared

func (UnimplementedBusiServer) QueryPreparedB

func (UnimplementedBusiServer) QueryPreparedRedis

func (UnimplementedBusiServer) QueryPreparedRedis(context.Context, *ReqGrpc) (*emptypb.Empty, error)

func (UnimplementedBusiServer) TransIn

func (UnimplementedBusiServer) TransInBSaga

func (UnimplementedBusiServer) TransInConfirm

func (UnimplementedBusiServer) TransInRedis

func (UnimplementedBusiServer) TransInRevert

func (UnimplementedBusiServer) TransInRevertBSaga

func (UnimplementedBusiServer) TransInRevertBSaga(context.Context, *ReqGrpc) (*emptypb.Empty, error)

func (UnimplementedBusiServer) TransInRevertRedis

func (UnimplementedBusiServer) TransInRevertRedis(context.Context, *ReqGrpc) (*emptypb.Empty, error)

func (UnimplementedBusiServer) TransInTcc

func (UnimplementedBusiServer) TransInTccNested

func (UnimplementedBusiServer) TransInXa

func (UnimplementedBusiServer) TransOut

func (UnimplementedBusiServer) TransOutBSaga

func (UnimplementedBusiServer) TransOutConfirm

func (UnimplementedBusiServer) TransOutHeaderNo

func (UnimplementedBusiServer) TransOutHeaderYes

func (UnimplementedBusiServer) TransOutRedis

func (UnimplementedBusiServer) TransOutRevert

func (UnimplementedBusiServer) TransOutRevertBSaga

func (UnimplementedBusiServer) TransOutRevertBSaga(context.Context, *ReqGrpc) (*emptypb.Empty, error)

func (UnimplementedBusiServer) TransOutRevertRedis

func (UnimplementedBusiServer) TransOutRevertRedis(context.Context, *ReqGrpc) (*emptypb.Empty, error)

func (UnimplementedBusiServer) TransOutTcc

func (UnimplementedBusiServer) TransOutXa

func (UnimplementedBusiServer) XaNotify

type UnsafeBusiServer

type UnsafeBusiServer interface {
	// contains filtered or unexported methods
}

UnsafeBusiServer may be embedded to opt out of forward compatibility for this service. Use of this interface is not recommended, as added methods to BusiServer will result in compilation errors.

type UserAccount

type UserAccount struct {
	UserID         int
	Balance        string
	TradingBalance string
}

UserAccount 1

func (*UserAccount) TableName

func (*UserAccount) TableName() string

TableName 1

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL