|
|
@@ -1,7 +1,7 @@
|
|
1
|
1
|
// Package configure 使用示例
|
|
2
|
2
|
//
|
|
3
|
3
|
// 以下示例演示如何使用配置中心客户端SDK
|
|
4
|
|
-package configure
|
|
|
4
|
+package test
|
|
5
|
5
|
|
|
6
|
6
|
import (
|
|
7
|
7
|
"context"
|
|
|
@@ -10,6 +10,7 @@ import (
|
|
10
|
10
|
"time"
|
|
11
|
11
|
|
|
12
|
12
|
"git.x2erp.com/qdy/go-base/model/request/queryreq"
|
|
|
13
|
+ "git.x2erp.com/qdy/go-base/sdk/configure"
|
|
13
|
14
|
)
|
|
14
|
15
|
|
|
15
|
16
|
// ExampleUsage 演示SDK的基本用法
|
|
|
@@ -34,7 +35,7 @@ func exampleCreateClient() {
|
|
34
|
35
|
fmt.Println("=== 示例1:创建客户端 ===")
|
|
35
|
36
|
|
|
36
|
37
|
// 方法1:使用默认配置
|
|
37
|
|
- client1, err := NewClient()
|
|
|
38
|
+ client1, err := configure.NewClient()
|
|
38
|
39
|
if err != nil {
|
|
39
|
40
|
log.Printf("Failed to create default client: %v", err)
|
|
40
|
41
|
} else {
|
|
|
@@ -42,14 +43,14 @@ func exampleCreateClient() {
|
|
42
|
43
|
}
|
|
43
|
44
|
|
|
44
|
45
|
// 方法2:使用Basic认证
|
|
45
|
|
- if _, err := NewBasicAuthClient("http://localhost:8080", "admin", "123"); err != nil {
|
|
|
46
|
+ if _, err := configure.NewBasicAuthClient("http://localhost:8080", "admin", "123"); err != nil {
|
|
46
|
47
|
log.Printf("Failed to create basic auth client: %v", err)
|
|
47
|
48
|
} else {
|
|
48
|
49
|
fmt.Println("Basic auth client created")
|
|
49
|
50
|
}
|
|
50
|
51
|
|
|
51
|
52
|
// 方法3:使用Token认证
|
|
52
|
|
- if _, err := NewTokenAuthClient("http://localhost:8080", "your-token-here"); err != nil {
|
|
|
53
|
+ if _, err := configure.NewTokenAuthClient("http://localhost:8080", "your-token-here"); err != nil {
|
|
53
|
54
|
log.Printf("Failed to create token auth client: %v", err)
|
|
54
|
55
|
} else {
|
|
55
|
56
|
fmt.Println("Token auth client created")
|
|
|
@@ -62,14 +63,14 @@ func exampleListTables() {
|
|
62
|
63
|
fmt.Println("=== 示例2:查询数据库表字典列表 ===")
|
|
63
|
64
|
|
|
64
|
65
|
// 创建客户端
|
|
65
|
|
- client, err := NewBasicAuthClient("http://localhost:8080", "admin", "123")
|
|
|
66
|
+ client, err := configure.NewBasicAuthClient("http://localhost:8080", "admin", "123")
|
|
66
|
67
|
if err != nil {
|
|
67
|
68
|
log.Printf("Failed to create client: %v", err)
|
|
68
|
69
|
return
|
|
69
|
70
|
}
|
|
70
|
71
|
|
|
71
|
72
|
// 创建查询请求
|
|
72
|
|
- query := &DicTableQueryRequest{
|
|
|
73
|
+ query := &configure.DicTableQueryRequest{
|
|
73
|
74
|
QueryRequest: queryreq.QueryRequest{
|
|
74
|
75
|
Page: 0,
|
|
75
|
76
|
PageSize: 10,
|
|
|
@@ -95,14 +96,14 @@ func exampleSaveTable() {
|
|
95
|
96
|
fmt.Println("=== 示例3:创建数据库表字典 ===")
|
|
96
|
97
|
|
|
97
|
98
|
// 创建客户端
|
|
98
|
|
- client, err := NewBasicAuthClient("http://localhost:8080", "admin", "123")
|
|
|
99
|
+ client, err := configure.NewBasicAuthClient("http://localhost:8080", "admin", "123")
|
|
99
|
100
|
if err != nil {
|
|
100
|
101
|
log.Printf("Failed to create client: %v", err)
|
|
101
|
102
|
return
|
|
102
|
103
|
}
|
|
103
|
104
|
|
|
104
|
105
|
// 创建请求
|
|
105
|
|
- req := &DicTableRequest{
|
|
|
106
|
+ req := &configure.DicTableRequest{
|
|
106
|
107
|
TableID: "example_table_001",
|
|
107
|
108
|
TableType: "实体表",
|
|
108
|
109
|
Name: "示例表001",
|
|
|
@@ -110,7 +111,7 @@ func exampleSaveTable() {
|
|
110
|
111
|
Creator: "admin",
|
|
111
|
112
|
CreatedAt: time.Now(),
|
|
112
|
113
|
UpdatedAt: time.Now(),
|
|
113
|
|
- Fields: []DicTableFieldRequest{
|
|
|
114
|
+ Fields: []configure.DicTableFieldRequest{
|
|
114
|
115
|
{
|
|
115
|
116
|
FieldID: "example_table_001.id",
|
|
116
|
117
|
TableID: "example_table_001",
|
|
|
@@ -158,7 +159,7 @@ func exampleGetTable() {
|
|
158
|
159
|
fmt.Println("=== 示例4:查询数据库表字典详情 ===")
|
|
159
|
160
|
|
|
160
|
161
|
// 创建客户端
|
|
161
|
|
- client, err := NewBasicAuthClient("http://localhost:8080", "admin", "123")
|
|
|
162
|
+ client, err := configure.NewBasicAuthClient("http://localhost:8080", "admin", "123")
|
|
162
|
163
|
if err != nil {
|
|
163
|
164
|
log.Printf("Failed to create client: %v", err)
|
|
164
|
165
|
return
|
|
|
@@ -171,7 +172,7 @@ func exampleGetTable() {
|
|
171
|
172
|
tableID := "example_table_001"
|
|
172
|
173
|
detail, err := client.GetTable(ctx, tableID)
|
|
173
|
174
|
if err != nil {
|
|
174
|
|
- if err == ErrNotFound {
|
|
|
175
|
+ if err == configure.ErrNotFound {
|
|
175
|
176
|
fmt.Printf("Table %s not found\n", tableID)
|
|
176
|
177
|
} else {
|
|
177
|
178
|
log.Printf("Error getting table: %v", err)
|
|
|
@@ -192,7 +193,7 @@ func exampleDeleteTable() {
|
|
192
|
193
|
fmt.Println("=== 示例5:删除数据库表字典 ===")
|
|
193
|
194
|
|
|
194
|
195
|
// 创建客户端
|
|
195
|
|
- client, err := NewBasicAuthClient("http://localhost:8080", "admin", "123")
|
|
|
196
|
+ client, err := configure.NewBasicAuthClient("http://localhost:8080", "admin", "123")
|
|
196
|
197
|
if err != nil {
|
|
197
|
198
|
log.Printf("Failed to create client: %v", err)
|
|
198
|
199
|
return
|
|
|
@@ -204,7 +205,7 @@ func exampleDeleteTable() {
|
|
204
|
205
|
|
|
205
|
206
|
tableID := "example_table_001"
|
|
206
|
207
|
if err := client.DeleteTable(ctx, tableID); err != nil {
|
|
207
|
|
- if err == ErrNotFound {
|
|
|
208
|
+ if err == configure.ErrNotFound {
|
|
208
|
209
|
fmt.Printf("Table %s not found\n", tableID)
|
|
209
|
210
|
} else {
|
|
210
|
211
|
log.Printf("Error deleting table: %v", err)
|