This is an automated email from the ASF dual-hosted git repository.

zfeng pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-seata-go-samples.git


The following commit(s) were added to refs/heads/main by this push:
     new fc9f144  Add two new actions: CodeQL and Lint. (#69)
fc9f144 is described below

commit fc9f144e91eeb9a3ddb8298d31fc172369962190
Author: FengZhang <[email protected]>
AuthorDate: Tue Jun 24 23:02:43 2025 +0800

    Add two new actions: CodeQL and Lint. (#69)
    
    * add action of codeql and lint
    
    * fix golangci-lint error
    
    * add golangci.yaml
---
 .github/workflows/codeql.yml        | 69 ++++++++++++++++++++++++++++
 .github/workflows/golangci-lint.yml | 60 ++++++++++++++++++++++++
 .golangci.yml                       | 92 +++++++++++++++++++++++++++++++++++++
 at/basic/insert.go                  |  2 +-
 at/basic/insert_on_update.go        |  2 +-
 at/basic/main.go                    |  6 +++
 at/basic/select_for_update.go       |  2 +-
 at/gorm/main.go                     | 12 ++++-
 at/grpc/cmd/client/main.go          |  6 ++-
 at/non_transaction/main.go          |  8 ++--
 at/rollback/client/main.go          |  2 +-
 integrate_test/at/insert/main.go    | 11 ++++-
 tcc/dubbo/client/cmd/client.go      |  2 +-
 tcc/fence/cmd/main.go               |  2 +-
 tcc/fence/service/service.go        | 30 +++++++-----
 tcc/gin/client/main.go              |  5 +-
 tcc/grpc/cmd/client/main.go         |  6 ++-
 tcc/local/cmd/local.go              |  2 +-
 util/db.go                          | 10 ++--
 xa/basic/insert.go                  |  2 +-
 xa/basic/insert_on_update.go        |  2 +-
 xa/basic/main.go                    | 12 +++--
 xa/basic/select_for_update.go       |  2 +-
 xa/gin/client/main.go               |  2 +-
 xa/gorm/main.go                     | 21 ++++++++-
 25 files changed, 326 insertions(+), 44 deletions(-)

diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml
new file mode 100644
index 0000000..9abedcc
--- /dev/null
+++ b/.github/workflows/codeql.yml
@@ -0,0 +1,69 @@
+#
+# 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.
+#
+
+# For most projects, this workflow file will not need changing; you simply need
+# to commit it to your repository.
+#
+# You may wish to alter this file to override the set of languages analyzed,
+# or to provide custom queries or build logic.
+#
+# ******** NOTE ********
+# We have attempted to detect the languages in your repository. Please check
+# the `language` matrix defined below to confirm you have the correct set of
+# supported CodeQL languages.
+#
+
+name: CodeQL
+
+on:
+  pull_request:
+    # The branches below must be a subset of the branches above
+    branches: "*"
+
+permissions:
+  contents: read
+
+jobs:
+  analyse:
+    permissions:
+      actions: read # for github/codeql-action/init to get workflow details
+      contents: read  # for actions/checkout to fetch code
+      security-events: write  # for github/codeql-action/autobuild to send a 
status report
+    name: Analyse
+    runs-on: ubuntu-latest
+
+    steps:
+      - name: Checkout repository
+        uses: actions/checkout@v3
+        with:
+          # We must fetch at least the immediate parents so that if this is
+          # a pull request then we can checkout the head.
+          fetch-depth: 2
+
+      # Initializes the CodeQL tools for scanning.
+      - name: Initialize CodeQL
+        uses: github/codeql-action/init@v2
+
+        # Autobuild attempts to build any compiled languages  (C/C++, C#, or 
Java).
+        # If this step fails, then you should remove it and run the build 
manually (see below)
+      - name: Autobuild
+        uses: github/codeql-action/autobuild@v2
+
+      # Analysis
+      - name: Perform CodeQL Analysis
+        uses: github/codeql-action/analyze@v2
+
diff --git a/.github/workflows/golangci-lint.yml 
b/.github/workflows/golangci-lint.yml
new file mode 100644
index 0000000..e92112e
--- /dev/null
+++ b/.github/workflows/golangci-lint.yml
@@ -0,0 +1,60 @@
+#
+# 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.
+#
+
+# This is a basic workflow to help you get started with Actions
+
+name: "golang ci lint"
+
+# Controls when the workflow will run
+on:
+  # Triggers the workflow on push or pull request events but only for the 
master branch
+  push:
+    branches: [ master ]
+  pull_request:
+    branches: "*"
+
+  # Allows you to run this workflow manually from the Actions tab
+#  workflow_dispatch:
+
+# A workflow run is made up of one or more jobs that can run sequentially or 
in parallel
+jobs:
+  # This workflow contains a single job called "build"
+  build:
+    # The type of runner that the job will run on
+    runs-on: ubuntu-latest
+    strategy:
+      matrix:
+        golang:
+          - 1.20.0
+
+    # Steps represent a sequence of tasks that will be executed as part of the 
job
+    steps:
+      - name: "set up go"
+        uses: actions/setup-go@v3
+        with:
+          go-version: 1.20.0
+
+      # Checks-out your repository under $GITHUB_WORKSPACE, so your job can 
access it
+      - name: "checkout ${{ github.ref }}"
+        uses: actions/checkout@v3
+
+      - name: "golang ci lint"
+        uses: golangci/[email protected]
+        with:
+          version: v1.51.0
+          args: --timeout=10m
+          skip-go-installation: true
diff --git a/.golangci.yml b/.golangci.yml
new file mode 100644
index 0000000..e558827
--- /dev/null
+++ b/.golangci.yml
@@ -0,0 +1,92 @@
+#
+# 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.
+#
+
+linters-settings:
+  govet:
+    shadow: true
+  golint:
+    min-confidence: 0
+  gocyclo:
+    min-complexity: 10
+  maligned:
+    suggest-new: true
+  dupl:
+    threshold: 100
+  goconst:
+    min-len: 2
+    min-occurrences: 2
+  depguard:
+    list-type: blacklist
+    packages:
+      # logging is allowed only by logutils.Log, logrus
+      # is allowed to use only in logutils package
+      - github.com/sirupsen/logrus
+  misspell:
+    locale: US
+  lll:
+    line-length: 140
+  goimports:
+    local-prefixes: github.com/golangci/golangci-lint
+  gocritic:
+    enabled-tags:
+      - performance
+      - style
+      - experimental
+    disabled-checks:
+      - wrapperFunc
+
+linters:
+  disable-all: true
+  enable:
+    - govet
+    - staticcheck
+    - ineffassign
+    - misspell
+    - asciicheck
+    - bodyclose
+    - rowserrcheck
+    - gofmt
+    - durationcheck
+    - sqlclosecheck
+
+run:
+
+issues:
+  exclude-dirs:
+    - test/testdata_etc
+    - pkg/golinters/goanalysis/(checker|passes)
+  exclude-rules:
+    - text: "weak cryptographic primitive"
+      linters:
+        - gosec
+    - linters:
+        - staticcheck
+      text: "SA1019:"
+    - path: _test\.go
+      linters:
+        - errcheck
+        - gosec
+        - rowserrcheck
+        - govet
+
+# golangci.com configuration
+# https://github.com/golangci/golangci/wiki/Configuration
+service:
+  golangci-lint-version: 1.57.x # use the fixed version to not introduce new 
linters unexpectedly
+  prepare:
+    - echo "here I can run custom commands, but no preparation needed for this 
repo"
+
diff --git a/at/basic/insert.go b/at/basic/insert.go
index 3d1adad..abbcb84 100644
--- a/at/basic/insert.go
+++ b/at/basic/insert.go
@@ -42,7 +42,7 @@ func insertData(ctx context.Context) error {
 }
 
 func sampleInsert(ctx context.Context) {
-       tm.WithGlobalTx(ctx, &tm.GtxConfig{
+       _ = tm.WithGlobalTx(ctx, &tm.GtxConfig{
                Name:    "ATSampleLocalGlobalTx_Insert",
                Timeout: time.Second * 30,
        }, insertData)
diff --git a/at/basic/insert_on_update.go b/at/basic/insert_on_update.go
index f0ad54f..ce3d706 100644
--- a/at/basic/insert_on_update.go
+++ b/at/basic/insert_on_update.go
@@ -43,7 +43,7 @@ func insertOnUpdateData(ctx context.Context) error {
 }
 
 func sampleInsertOnUpdate(ctx context.Context) {
-       tm.WithGlobalTx(ctx, &tm.GtxConfig{
+       _ = tm.WithGlobalTx(ctx, &tm.GtxConfig{
                Name:    "ATSampleLocalGlobalTx_InsertOnUpdate",
                Timeout: time.Second * 30,
        }, insertOnUpdateData)
diff --git a/at/basic/main.go b/at/basic/main.go
index 7eb17b5..6099bcc 100644
--- a/at/basic/main.go
+++ b/at/basic/main.go
@@ -43,6 +43,12 @@ func main() {
        // sample: select for udpate
        sampleSelectForUpdate(ctx)
 
+       // updateData
+       _ = updateData(ctx)
+
+       // deleteData
+       _ = deleteData(ctx)
+
        <-make(chan struct{})
 }
 
diff --git a/at/basic/select_for_update.go b/at/basic/select_for_update.go
index 124fc36..593712c 100644
--- a/at/basic/select_for_update.go
+++ b/at/basic/select_for_update.go
@@ -42,7 +42,7 @@ func selectForUpdateData(ctx context.Context) error {
 }
 
 func sampleSelectForUpdate(ctx context.Context) {
-       tm.WithGlobalTx(ctx, &tm.GtxConfig{
+       _ = tm.WithGlobalTx(ctx, &tm.GtxConfig{
                Name:    "ATSampleLocalGlobalTx_SelectForUpdate",
                Timeout: time.Second * 30,
        }, selectForUpdateData)
diff --git a/at/gorm/main.go b/at/gorm/main.go
index 45b9aa3..e2a3e54 100644
--- a/at/gorm/main.go
+++ b/at/gorm/main.go
@@ -41,10 +41,17 @@ type OrderTblModel struct {
 func main() {
        initConfig()
        // insert
-       tm.WithGlobalTx(context.Background(), &tm.GtxConfig{
+       _ = tm.WithGlobalTx(context.Background(), &tm.GtxConfig{
                Name:    "ATSampleLocalGlobalTx",
                Timeout: time.Second * 30,
        }, insertData)
+
+       // update
+       _ = updateData(context.Background())
+
+       // delete
+       _ = deleteData(context.Background())
+
        <-make(chan struct{})
 }
 
@@ -66,6 +73,9 @@ func initDB() {
        gormDB, err = gorm.Open(mysql.New(mysql.Config{
                Conn: sqlDB,
        }), &gorm.Config{})
+       if err != nil {
+               panic("open DB error")
+       }
 }
 
 // insertData insert one data
diff --git a/at/grpc/cmd/client/main.go b/at/grpc/cmd/client/main.go
index 2e27269..0558db4 100644
--- a/at/grpc/cmd/client/main.go
+++ b/at/grpc/cmd/client/main.go
@@ -41,11 +41,13 @@ func main() {
        if err != nil {
                log.Fatalf("did not connect: %v", err)
        }
-       defer conn.Close()
+       defer func() {
+               _ = conn.Close()
+       }()
        businessClient := __.NewATServiceBusinessClient(conn)
 
        client.InitPath("../../../../conf/seatago.yml")
-       tm.WithGlobalTx(
+       _ = tm.WithGlobalTx(
                context.Background(),
                &tm.GtxConfig{
                        Name: "XASampleLocalGlobalTx",
diff --git a/at/non_transaction/main.go b/at/non_transaction/main.go
index 7845d92..544440c 100644
--- a/at/non_transaction/main.go
+++ b/at/non_transaction/main.go
@@ -51,21 +51,21 @@ func main() {
 
        insertId := insertData()
 
-       // insertDuplicateData(insertId)
+       insertDuplicateData(insertId)
 
        selectData(insertId)
 
-       updateData(insertId)
+       _ = updateData(insertId)
 
        selectData(insertId)
 
-       deleteData(insertId)
+       _ = deleteData(insertId)
 
        selectData(insertId)
 
        userIds := batchInsertData()
 
-       batchDeleteData(userIds)
+       _ = batchDeleteData(userIds)
 
        <-make(chan struct{})
 }
diff --git a/at/rollback/client/main.go b/at/rollback/client/main.go
index feb8b11..565b00c 100644
--- a/at/rollback/client/main.go
+++ b/at/rollback/client/main.go
@@ -40,5 +40,5 @@ func main() {
        sampleUpdate(bgCtx)
 
        // sample insert on update
-       // sampleInsertOnUpdate(bgCtx)
+       sampleInsertOnUpdate(bgCtx)
 }
diff --git a/integrate_test/at/insert/main.go b/integrate_test/at/insert/main.go
index 58d4193..fde37fd 100644
--- a/integrate_test/at/insert/main.go
+++ b/integrate_test/at/insert/main.go
@@ -21,6 +21,7 @@ import (
        "context"
        "database/sql"
        "fmt"
+       "log"
        "time"
 
        "gorm.io/driver/mysql"
@@ -43,11 +44,16 @@ func main() {
        initConfig()
 
        // test: insert
-       tm.WithGlobalTx(context.Background(), &tm.GtxConfig{
+       err := tm.WithGlobalTx(context.Background(), &tm.GtxConfig{
                Name:    "ATSampleLocalGlobalTx",
                Timeout: time.Second * 30,
        }, insertData)
 
+       if err != nil {
+               log.Fatalf("failed to init transaction: %v", err)
+               return
+       }
+
        ctx := context.Background()
 
        // check
@@ -78,6 +84,9 @@ func initDB() {
        gormDB, err = gorm.Open(mysql.New(mysql.Config{
                Conn: sqlDB,
        }), &gorm.Config{})
+       if err != nil {
+               panic("open DB error")
+       }
 }
 
 func getData() OrderTblModel {
diff --git a/tcc/dubbo/client/cmd/client.go b/tcc/dubbo/client/cmd/client.go
index 621c7e0..31417b0 100644
--- a/tcc/dubbo/client/cmd/client.go
+++ b/tcc/dubbo/client/cmd/client.go
@@ -40,7 +40,7 @@ func main() {
 }
 
 func run() {
-       tm.WithGlobalTx(context.Background(), &tm.GtxConfig{
+       _ = tm.WithGlobalTx(context.Background(), &tm.GtxConfig{
                Name: "TccSampleLocalGlobalTx",
        }, business)
        <-make(chan struct{})
diff --git a/tcc/fence/cmd/main.go b/tcc/fence/cmd/main.go
index 0c25628..05e3f86 100644
--- a/tcc/fence/cmd/main.go
+++ b/tcc/fence/cmd/main.go
@@ -30,7 +30,7 @@ import (
 
 func main() {
        client.InitPath("../../../conf/seatago.yml")
-       tm.WithGlobalTx(context.Background(), &tm.GtxConfig{
+       _ = tm.WithGlobalTx(context.Background(), &tm.GtxConfig{
                Name: "TccSampleLocalGlobalTx",
        }, business)
        <-make(chan struct{})
diff --git a/tcc/fence/service/service.go b/tcc/fence/service/service.go
index 34ea3fb..8680d2b 100644
--- a/tcc/fence/service/service.go
+++ b/tcc/fence/service/service.go
@@ -40,12 +40,6 @@ var (
 
        tccService2     *tcc.TCCServiceProxy
        tccService2Once sync.Once
-
-       commitTimes      int
-       commitFenceTimes int
-
-       rollbackTimes      int
-       rollbackFenceTimes int
 )
 
 type TestTCCServiceBusiness struct{}
@@ -69,7 +63,9 @@ func (T TestTCCServiceBusiness) Prepare(ctx context.Context, 
params interface{})
        if err != nil {
                return false, fmt.Errorf("database connect failed, msg :%s", 
err.Error())
        }
-       defer db.Close()
+       defer func() {
+               _ = db.Close()
+       }()
        tx, err := db.Begin()
        if err != nil {
                return false, fmt.Errorf("transaction begin failed, msg :%s", 
err.Error())
@@ -96,7 +92,9 @@ func (T TestTCCServiceBusiness) Commit(ctx context.Context, 
businessActionContex
        if err != nil {
                return false, fmt.Errorf("database connect failed, msg :%s", 
err.Error())
        }
-       defer db.Close()
+       defer func() {
+               _ = db.Close()
+       }()
        tx, err := db.Begin()
        if err != nil {
                return false, fmt.Errorf("transaction begin failed, msg :%s", 
err.Error())
@@ -123,7 +121,9 @@ func (T TestTCCServiceBusiness) Rollback(ctx 
context.Context, businessActionCont
        if err != nil {
                return false, fmt.Errorf("database connect failed, msg :%s", 
err.Error())
        }
-       defer db.Close()
+       defer func() {
+               _ = db.Close()
+       }()
        tx, err := db.Begin()
        if err != nil {
                return false, fmt.Errorf("transaction begin failed, msg :%s", 
err.Error())
@@ -173,7 +173,9 @@ func (T TestTCCServiceBusiness2) Prepare(ctx 
context.Context, params interface{}
        if err != nil {
                return false, fmt.Errorf("database connect failed, msg :%s", 
err.Error())
        }
-       defer db.Close()
+       defer func() {
+               _ = db.Close()
+       }()
        tx, err := db.Begin()
        if err != nil {
                return false, fmt.Errorf("transaction begin failed, msg :%s", 
err.Error())
@@ -200,7 +202,9 @@ func (T TestTCCServiceBusiness2) Commit(ctx 
context.Context, businessActionConte
        if err != nil {
                return false, fmt.Errorf("database connect failed, msg :%s", 
err.Error())
        }
-       defer db.Close()
+       defer func() {
+               _ = db.Close()
+       }()
        tx, err := db.Begin()
        if err != nil {
                return false, fmt.Errorf("transaction begin failed, msg :%s", 
err.Error())
@@ -227,7 +231,9 @@ func (T TestTCCServiceBusiness2) Rollback(ctx 
context.Context, businessActionCon
        if err != nil {
                return false, fmt.Errorf("database connect failed, msg :%s", 
err.Error())
        }
-       defer db.Close()
+       defer func() {
+               _ = db.Close()
+       }()
        tx, err := db.Begin()
        if err != nil {
                return false, fmt.Errorf("transaction begin failed, msg :%s", 
err.Error())
diff --git a/tcc/gin/client/main.go b/tcc/gin/client/main.go
index 4c49095..6adc01b 100644
--- a/tcc/gin/client/main.go
+++ b/tcc/gin/client/main.go
@@ -37,7 +37,7 @@ func main() {
        defer cancel()
        serverIpPort := "http://127.0.0.1:8080";
 
-       tm.WithGlobalTx(
+       err := tm.WithGlobalTx(
                bgCtx,
                &tm.GtxConfig{
                        Name: "TccSampleLocalGlobalTx",
@@ -54,4 +54,7 @@ func main() {
                                })
                        return
                })
+       if err != nil {
+               log.Fatalf(err.Error())
+       }
 }
diff --git a/tcc/grpc/cmd/client/main.go b/tcc/grpc/cmd/client/main.go
index 0634e3e..7388e30 100644
--- a/tcc/grpc/cmd/client/main.go
+++ b/tcc/grpc/cmd/client/main.go
@@ -42,12 +42,14 @@ func main() {
        if err != nil {
                log.Fatalf("did not connect: %v", err)
        }
-       defer conn.Close()
+       defer func() {
+               _ = conn.Close()
+       }()
        c1, c2 := pb.NewTCCServiceBusiness1Client(conn), 
pb.NewTCCServiceBusiness2Client(conn)
 
        client.InitPath("../../../../conf/seatago.yml")
 
-       tm.WithGlobalTx(
+       _ = tm.WithGlobalTx(
                context.Background(),
                &tm.GtxConfig{
                        Name: "TccSampleLocalGlobalTx",
diff --git a/tcc/local/cmd/local.go b/tcc/local/cmd/local.go
index 2c5ae5d..826fbb2 100644
--- a/tcc/local/cmd/local.go
+++ b/tcc/local/cmd/local.go
@@ -28,7 +28,7 @@ import (
 
 func main() {
        client.InitPath("../../../conf/seatago.yml")
-       tm.WithGlobalTx(context.Background(), &tm.GtxConfig{
+       _ = tm.WithGlobalTx(context.Background(), &tm.GtxConfig{
                Name: "TccSampleLocalGlobalTx",
        }, business)
        <-make(chan struct{})
diff --git a/util/db.go b/util/db.go
index b904e9e..b83fbab 100644
--- a/util/db.go
+++ b/util/db.go
@@ -46,18 +46,18 @@ func GetXAMySqlDb() *sql.DB {
 
 func defaultEnv() {
        if os.Getenv("MYSQL_HOST") == "" {
-               os.Setenv("MYSQL_HOST", "127.0.0.1")
+               _ = os.Setenv("MYSQL_HOST", "127.0.0.1")
        }
        if os.Getenv("MYSQL_PORT") == "" {
-               os.Setenv("MYSQL_PORT", "3306")
+               _ = os.Setenv("MYSQL_PORT", "3306")
        }
        if os.Getenv("MYSQL_USERNAME") == "" {
-               os.Setenv("MYSQL_USERNAME", "root")
+               _ = os.Setenv("MYSQL_USERNAME", "root")
        }
        if os.Getenv("MYSQL_PASSWORD") == "" {
-               os.Setenv("MYSQL_PASSWORD", "123456")
+               _ = os.Setenv("MYSQL_PASSWORD", "123456")
        }
        if os.Getenv("MYSQL_DB") == "" {
-               os.Setenv("MYSQL_DB", "seata_client")
+               _ = os.Setenv("MYSQL_DB", "seata_client")
        }
 }
diff --git a/xa/basic/insert.go b/xa/basic/insert.go
index d220c01..4a1673a 100644
--- a/xa/basic/insert.go
+++ b/xa/basic/insert.go
@@ -42,7 +42,7 @@ func insertData(ctx context.Context) error {
 }
 
 func sampleInsert(ctx context.Context) {
-       tm.WithGlobalTx(ctx, &tm.GtxConfig{
+       _ = tm.WithGlobalTx(ctx, &tm.GtxConfig{
                Name:    "XASampleLocalGlobalTx_Insert",
                Timeout: time.Second * 30,
        }, insertData)
diff --git a/xa/basic/insert_on_update.go b/xa/basic/insert_on_update.go
index f0ad54f..ce3d706 100644
--- a/xa/basic/insert_on_update.go
+++ b/xa/basic/insert_on_update.go
@@ -43,7 +43,7 @@ func insertOnUpdateData(ctx context.Context) error {
 }
 
 func sampleInsertOnUpdate(ctx context.Context) {
-       tm.WithGlobalTx(ctx, &tm.GtxConfig{
+       _ = tm.WithGlobalTx(ctx, &tm.GtxConfig{
                Name:    "ATSampleLocalGlobalTx_InsertOnUpdate",
                Timeout: time.Second * 30,
        }, insertOnUpdateData)
diff --git a/xa/basic/main.go b/xa/basic/main.go
index 9b9dfc7..153f21b 100644
--- a/xa/basic/main.go
+++ b/xa/basic/main.go
@@ -38,10 +38,16 @@ func main() {
        sampleInsert(ctx)
 
        // sample: insert on update
-       //sampleInsertOnUpdate(ctx)
+       sampleInsertOnUpdate(ctx)
 
-       // sample: select for udpate
-       //sampleSelectForUpdate(ctx)
+       // sample: select for update
+       sampleSelectForUpdate(ctx)
+
+       // deleteData
+       _ = deleteData(ctx)
+
+       // deleteData
+       _ = updateData(ctx)
 
        <-make(chan struct{})
 }
diff --git a/xa/basic/select_for_update.go b/xa/basic/select_for_update.go
index 124fc36..593712c 100644
--- a/xa/basic/select_for_update.go
+++ b/xa/basic/select_for_update.go
@@ -42,7 +42,7 @@ func selectForUpdateData(ctx context.Context) error {
 }
 
 func sampleSelectForUpdate(ctx context.Context) {
-       tm.WithGlobalTx(ctx, &tm.GtxConfig{
+       _ = tm.WithGlobalTx(ctx, &tm.GtxConfig{
                Name:    "ATSampleLocalGlobalTx_SelectForUpdate",
                Timeout: time.Second * 30,
        }, selectForUpdateData)
diff --git a/xa/gin/client/main.go b/xa/gin/client/main.go
index 7064e99..524cb3f 100644
--- a/xa/gin/client/main.go
+++ b/xa/gin/client/main.go
@@ -38,7 +38,7 @@ func main() {
        sampleUpdate(bgCtx)
 
        // sample insert on update
-       //sampleInsertOnUpdate(bgCtx)
+       sampleInsertOnUpdate(bgCtx)
 
        // sample select for update
        sampleSelectForUpdate(bgCtx)
diff --git a/xa/gorm/main.go b/xa/gorm/main.go
index 4f32eab..a40b37b 100644
--- a/xa/gorm/main.go
+++ b/xa/gorm/main.go
@@ -41,11 +41,25 @@ type OrderTblModel struct {
 func main() {
        initConfig()
        // insert
-       tm.WithGlobalTx(context.Background(), &tm.GtxConfig{
+       _ = tm.WithGlobalTx(context.Background(), &tm.GtxConfig{
                Name:    "ATSampleLocalGlobalTx",
                Timeout: time.Second * 30,
        }, insertData)
-       <-make(chan struct{})
+       time.Sleep(time.Second * 40)
+
+       // updateData
+       _ = tm.WithGlobalTx(context.Background(), &tm.GtxConfig{
+               Name:    "ATSampleLocalGlobalTx",
+               Timeout: time.Second * 30,
+       }, updateData)
+       time.Sleep(time.Second * 40)
+
+       // deleteData
+       _ = tm.WithGlobalTx(context.Background(), &tm.GtxConfig{
+               Name:    "ATSampleLocalGlobalTx",
+               Timeout: time.Second * 30,
+       }, deleteData)
+       time.Sleep(time.Second * 40)
 }
 
 func initConfig() {
@@ -66,6 +80,9 @@ func initDB() {
        gormDB, err = gorm.Open(mysql.New(mysql.Config{
                Conn: sqlDB,
        }), &gorm.Config{})
+       if err != nil {
+               panic("open DB error")
+       }
 }
 
 // insertData insert one data


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to