Bläddra i källkod

修改日志输出格式

qdy 2 månader sedan
förälder
incheckning
a063f9e08a
7 ändrade filer med 51 tillägg och 93 borttagningar
  1. 7
    6
      functions/query_csv.go
  2. 7
    6
      functions/query_json.go
  3. 17
    74
      gct.sh
  4. 9
    4
      main.go
  5. 5
    1
      test/my0_test.go
  6. 5
    1
      test/my_ora_clothingToDoris_test.go
  7. 1
    1
      test/mycsv_test.go

+ 7
- 6
functions/query_csv.go Visa fil

@@ -3,13 +3,14 @@ package functions
3 3
 import (
4 4
 	"log"
5 5
 
6
+	"git.x2erp.com/qdy/go-base/ctx"
6 7
 	"git.x2erp.com/qdy/go-base/types"
7 8
 	"git.x2erp.com/qdy/go-db/factory/database"
8 9
 )
9 10
 
10 11
 // 执行查询,返回CSV数据格式。无参数查询
11
-func QueryToCSV(dbFactory *database.DBFactory, req types.QueryRequest) []byte {
12
-	csvData, err := dbFactory.QueryToCSV(req.SQL, req.WriterHeader)
12
+func QueryToCSV(dbFactory *database.DBFactory, req types.QueryRequest, reqCtx *ctx.RequestContext) []byte {
13
+	csvData, err := dbFactory.QueryToCSV(req.SQL, req.WriterHeader, reqCtx)
13 14
 	if err != nil {
14 15
 		log.Fatalf("QueryToCSV error: %v", err)
15 16
 
@@ -18,9 +19,9 @@ func QueryToCSV(dbFactory *database.DBFactory, req types.QueryRequest) []byte {
18 19
 }
19 20
 
20 21
 // 执行查询,返回CSV数据格式。带参数名称进行查询
21
-func QueryParamNameToCSV(dbFactory *database.DBFactory, req types.QueryRequest) []byte {
22
+func QueryParamNameToCSV(dbFactory *database.DBFactory, req types.QueryRequest, reqCtx *ctx.RequestContext) []byte {
22 23
 
23
-	csvData, err := dbFactory.QueryParamsNameToCSV(req.SQL, req.WriterHeader, req.Params)
24
+	csvData, err := dbFactory.QueryParamsNameToCSV(req.SQL, req.WriterHeader, req.Params, reqCtx)
24 25
 	if err != nil {
25 26
 		log.Fatalf("QueryParamNameToCSV Error: %v", err)
26 27
 
@@ -29,8 +30,8 @@ func QueryParamNameToCSV(dbFactory *database.DBFactory, req types.QueryRequest)
29 30
 }
30 31
 
31 32
 // 执行查询,返回CSV数据格式。带占位参数进行查询
32
-func QueryPositionalToCSV(dbFactory *database.DBFactory, req types.QueryRequest) []byte {
33
-	csvData, err := dbFactory.QueryPositionalToCSV(req.SQL, req.WriterHeader, req.PositionalParams)
33
+func QueryPositionalToCSV(dbFactory *database.DBFactory, req types.QueryRequest, reqCtx *ctx.RequestContext) []byte {
34
+	csvData, err := dbFactory.QueryPositionalToCSV(req.SQL, req.WriterHeader, req.PositionalParams, reqCtx)
34 35
 	if err != nil {
35 36
 		log.Fatalf("QueryParamNameToCSV Error: %v", err)
36 37
 

+ 7
- 6
functions/query_json.go Visa fil

@@ -1,23 +1,24 @@
1 1
 package functions
2 2
 
3 3
 import (
4
+	"git.x2erp.com/qdy/go-base/ctx"
4 5
 	"git.x2erp.com/qdy/go-base/types"
5 6
 	"git.x2erp.com/qdy/go-db/factory/database"
6 7
 )
7 8
 
8 9
 // 执行查询,返回CSV数据格式。无参数查询
9
-func QueryToJSON(dbFactory *database.DBFactory, req types.QueryRequest) *types.QueryResult {
10
-	return dbFactory.QueryToJSON(req.SQL)
10
+func QueryToJSON(dbFactory *database.DBFactory, req types.QueryRequest, reqCtx *ctx.RequestContext) *types.QueryResult {
11
+	return dbFactory.QueryToJSON(req.SQL, reqCtx)
11 12
 
12 13
 }
13 14
 
14 15
 // 执行查询,返回CSV数据格式。带参数名称进行查询
15
-func QueryParamNameToJSON(dbFactory *database.DBFactory, req types.QueryRequest) *types.QueryResult {
16
-	return dbFactory.QueryParamsNameToJSON(req.SQL, req.Params)
16
+func QueryParamNameToJSON(dbFactory *database.DBFactory, req types.QueryRequest, reqCtx *ctx.RequestContext) *types.QueryResult {
17
+	return dbFactory.QueryParamsNameToJSON(req.SQL, req.Params, reqCtx)
17 18
 }
18 19
 
19 20
 // 执行查询,返回JSON数据格式。带占位参数进行查询
20
-func QueryPositionalToJSON(dbFactory *database.DBFactory, req types.QueryRequest) *types.QueryResult {
21
-	return dbFactory.QueryPositionalToJSON(req.SQL, req.PositionalParams)
21
+func QueryPositionalToJSON(dbFactory *database.DBFactory, req types.QueryRequest, reqCtx *ctx.RequestContext) *types.QueryResult {
22
+	return dbFactory.QueryPositionalToJSON(req.SQL, req.PositionalParams, reqCtx)
22 23
 
23 24
 }

+ 17
- 74
gct.sh Visa fil

@@ -1,82 +1,25 @@
1 1
 #!/bin/bash
2 2
 
3
-# 脚本用法:./git-commit-and-tag.sh "你的提交描述" "版本号"
3
+# 使用命令行参数,如果没有提供则使用默认值
4
+COMMIT_MSG="${1:-初始提交}"
5
+TAG_VERSION="${2:-v0.1.0}"
4 6
 
5
-# 检查参数数量
6
-if [ $# -ne 2 ]; then
7
-    echo "错误: 脚本需要2个参数。"
8
-    echo "用法: $0 \"提交描述\" \"版本号\""
9
-    echo "示例: $0 \"修复了登录问题\" \"v1.2.3\""
10
-    exit 1
11
-fi
7
+echo "提交信息: $COMMIT_MSG"
8
+echo "标签版本: $TAG_VERSION"
12 9
 
13
-# 分配参数
14
-COMMIT_MESSAGE="$1"
15
-VERSION_TAG="$2"
10
+# 提交和推送
11
+git add .
12
+git commit -m "$COMMIT_MSG"
13
+git push -u origin master
16 14
 
17
-# 检查当前目录是否为Git仓库
18
-if ! git rev-parse --git-dir > /dev/null 2>&1; then
19
-    echo "错误: 当前目录不是一个Git仓库。"
20
-    exit 1
21
-fi
15
+# 创建标签(关键修改在这里)
16
+# 方法1:使用注释标签(推荐,不会打开编辑器)
17
+git tag -a "$TAG_VERSION" -m "Release $TAG_VERSION"
22 18
 
23
-echo "开始处理提交和版本标签..."
24
-echo "提交描述: $COMMIT_MESSAGE"
25
-echo "版本标签: $VERSION_TAG"
19
+# 或者方法2:如果你需要GPG签名,使用这个
20
+# GIT_EDITOR=true git tag -s "$TAG_VERSION" -m "Release $TAG_VERSION"
26 21
 
27
-# 检查是否有未提交的更改
28
-if [ -n "$(git status --porcelain)" ]; then
29
-    echo "检测到未提交的更改,正在提交..."
30
-    
31
-    # 添加所有更改到暂存区
32
-    git add .
33
-    
34
-    # 进行提交
35
-    git commit -m "$COMMIT_MESSAGE"
36
-    if [ $? -ne 0 ]; then
37
-        echo "错误: 提交失败。"
38
-        exit 1
39
-    fi
40
-    echo "✅ 更改已提交"
41
-else
42
-    echo "提示: 没有未提交的更改,跳过提交步骤"
43
-    
44
-    # 检查是否有未提交的commit但未推送
45
-    LOCAL_COMMITS=$(git log @{u}..HEAD --oneline 2>/dev/null | wc -l)
46
-    if [ $LOCAL_COMMITS -eq 0 ]; then
47
-        echo "错误: 没有需要推送的提交。"
48
-        exit 1
49
-    else
50
-        echo "检测到 $LOCAL_COMMITS 个本地提交等待推送"
51
-    fi
52
-fi
22
+# 推送标签
23
+git push origin "$TAG_VERSION"
53 24
 
54
-# 检查标签是否已存在
55
-if git rev-parse "$VERSION_TAG" >/dev/null 2>&1; then
56
-    echo "错误: 标签 '$VERSION_TAG' 已经存在。"
57
-    exit 1
58
-fi
59
-
60
-# 创建标签
61
-git tag "$VERSION_TAG"
62
-if [ $? -ne 0 ]; then
63
-    echo "错误: 创建标签失败。"
64
-    exit 1
65
-fi
66
-echo "✅ 标签 '$VERSION_TAG' 已创建"
67
-
68
-# 推送到远程仓库并推送标签
69
-echo "正在推送到远程仓库..."
70
-git push
71
-if [ $? -ne 0 ]; then
72
-    echo "错误: 推送提交失败。"
73
-    exit 1
74
-fi
75
-
76
-git push origin "$VERSION_TAG"
77
-if [ $? -ne 0 ]; then
78
-    echo "错误: 推送标签失败。"
79
-    exit 1
80
-fi
81
-
82
-echo "✅ 完成!提交已推送,版本标签 $VERSION_TAG 已创建并推送。"
25
+echo "完成!"

+ 9
- 4
main.go Visa fil

@@ -17,7 +17,12 @@ import (
17 17
 )
18 18
 
19 19
 func main() {
20
-	cfg := config.GetConfig()
20
+	cfg, err := config.GetConfig()
21
+	if err != nil {
22
+		log.Printf("failed to load config: %v", err)
23
+		return
24
+	}
25
+
21 26
 	serviceConfig := cfg.GetService()
22 27
 
23 28
 	log.Printf("Service Port: %d", serviceConfig.Port)
@@ -32,12 +37,12 @@ func main() {
32 37
 	log.Println("Database connection test passed!")
33 38
 
34 39
 	// 启动微服务
35
-	startMicroService()
40
+	startMicroService(cfg)
36 41
 }
37 42
 
38 43
 // 启动微服务
39
-func startMicroService() {
40
-	cfg := config.GetConfig()
44
+func startMicroService(cfg config.IConfig) {
45
+
41 46
 	serviceConfig := cfg.GetService()
42 47
 
43 48
 	// 初始化数据库

+ 5
- 1
test/my0_test.go Visa fil

@@ -73,7 +73,11 @@ func TestQueryAndInsertToDoris1(t *testing.T) {
73 73
 	fmt.Println("Checking Doris table structure...")
74 74
 
75 75
 	// 获取Doris配置
76
-	cfg := config.GetConfig()
76
+	cfg, err := config.GetConfig()
77
+	if err != nil {
78
+		t.Fatalf("failed to load config: %v", err)
79
+		return
80
+	}
77 81
 	database := "X6_STOCK_DEV"
78 82
 	table := "A3_CLOTHING_LOG"
79 83
 	skipHeader := false // 改为true,跳过CSV头行

+ 5
- 1
test/my_ora_clothingToDoris_test.go Visa fil

@@ -76,7 +76,11 @@ func TestQueryAndInsertToDoris(t *testing.T) {
76 76
 	fmt.Println("Checking Doris table structure...")
77 77
 
78 78
 	// 获取Doris配置
79
-	cfg := config.GetConfig()
79
+	cfg, err := config.GetConfig()
80
+	if err != nil {
81
+		fmt.Println("failed to load config: %v", err)
82
+		return
83
+	}
80 84
 	database := "X6_STOCK_DEV"
81 85
 	table := "A3_CLOTHING"
82 86
 	skipHeader := false // 改为true,跳过CSV头行

+ 1
- 1
test/mycsv_test.go Visa fil

@@ -48,7 +48,7 @@ func TestNamedParamsQueryCSV(t *testing.T) {
48 48
 	// }
49 49
 
50 50
 	// 执行查询
51
-	result := factory.QueryPositionalToJSON(sql, params)
51
+	result := factory.QueryPositionalToJSON(sql, params, nil)
52 52
 
53 53
 	// 检查结果 - 根据你的错误信息,result.Error 是 string 类型
54 54
 	if err != nil { // 改成检查空字符串

Loading…
Avbryt
Spara