thunguo commented on code in PR #96: URL: https://github.com/apache/incubator-seata-go-samples/pull/96#discussion_r3408028279
########## xa/bank_transfer/bank-a-service/main.go: ########## @@ -0,0 +1,158 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package main + +import ( + "context" + "database/sql" + "errors" + "fmt" + "net/http" + "os" + + "github.com/gin-gonic/gin" + "seata.apache.org/seata-go/pkg/client" + sql2 "seata.apache.org/seata-go/pkg/datasource/sql" + ginmiddleware "seata.apache.org/seata-go/pkg/integration/gin" +) + +const defaultListenAddr = ":18081" + +var db *sql.DB + +type debitRequest struct { + AccountNo string `json:"account_no" binding:"required"` + Amount int64 `json:"amount" binding:"required,gt=0"` +} + +type account struct { + AccountNo string `json:"account_no"` + Balance int64 `json:"balance"` +} + +func main() { + client.InitPath(resolveSeataConfig()) + db = openXADB() + defer db.Close() + + r := gin.Default() + r.ContextWithFallback = true + r.GET("/accounts/:accountNo", accountHandler) + r.Use(ginmiddleware.TransactionMiddleware()) + r.POST("/debit", debitHandler) Review Comment: 这里GET Use POST顺序是正确的,不过可以补充一些注释说明一下意图,方便后续可能的迭代 -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
