|
|
@@ -78,7 +78,7 @@ func (c *Client) ListTables(ctx context.Context, query *DicTableQueryRequest) (*
|
|
78
|
78
|
endpoint := "/api/dic-table/list"
|
|
79
|
79
|
|
|
80
|
80
|
var result ResponseWrapper[[]DicTableDB]
|
|
81
|
|
- if err := c.doRequest(ctx, http.MethodPost, endpoint, query, &result); err != nil {
|
|
|
81
|
+ if err := c.doRequest(ctx, http.MethodPost, endpoint, query, &result, false); err != nil {
|
|
82
|
82
|
return nil, err
|
|
83
|
83
|
}
|
|
84
|
84
|
|
|
|
@@ -98,7 +98,7 @@ func (c *Client) GetTable(ctx context.Context, tableID string) (*DicTableDetail,
|
|
98
|
98
|
endpoint := fmt.Sprintf("/api/dic-table/detail/%s", tableID)
|
|
99
|
99
|
|
|
100
|
100
|
var result ResponseWrapper[DicTableDetail]
|
|
101
|
|
- if err := c.doRequest(ctx, http.MethodPost, endpoint, nil, &result); err != nil {
|
|
|
101
|
+ if err := c.doRequest(ctx, http.MethodPost, endpoint, nil, &result, false); err != nil {
|
|
102
|
102
|
return nil, err
|
|
103
|
103
|
}
|
|
104
|
104
|
|
|
|
@@ -127,7 +127,7 @@ func (c *Client) SaveTable(ctx context.Context, req *DicTableRequest) (*DicTable
|
|
127
|
127
|
endpoint := "/api/dic-table/save"
|
|
128
|
128
|
|
|
129
|
129
|
var result ResponseWrapper[DicTableDetail]
|
|
130
|
|
- if err := c.doRequest(ctx, http.MethodPost, endpoint, req, &result); err != nil {
|
|
|
130
|
+ if err := c.doRequest(ctx, http.MethodPost, endpoint, req, &result, false); err != nil {
|
|
131
|
131
|
return nil, err
|
|
132
|
132
|
}
|
|
133
|
133
|
|
|
|
@@ -143,7 +143,7 @@ func (c *Client) DeleteTable(ctx context.Context, tableID string) error {
|
|
143
|
143
|
endpoint := fmt.Sprintf("/api/dic-table/delete/%s", tableID)
|
|
144
|
144
|
|
|
145
|
145
|
var result ResponseWrapper[int64]
|
|
146
|
|
- if err := c.doRequest(ctx, http.MethodPost, endpoint, nil, &result); err != nil {
|
|
|
146
|
+ if err := c.doRequest(ctx, http.MethodPost, endpoint, nil, &result, false); err != nil {
|
|
147
|
147
|
return err
|
|
148
|
148
|
}
|
|
149
|
149
|
|
|
|
@@ -159,7 +159,7 @@ func (c *Client) BatchSaveTables(ctx context.Context, req *BatchSaveDicTablesReq
|
|
159
|
159
|
endpoint := "/api/dic-table/batch-save"
|
|
160
|
160
|
|
|
161
|
161
|
var result ResponseWrapper[bool]
|
|
162
|
|
- if err := c.doRequest(ctx, http.MethodPost, endpoint, req, &result); err != nil {
|
|
|
162
|
+ if err := c.doRequest(ctx, http.MethodPost, endpoint, req, &result, false); err != nil {
|
|
163
|
163
|
return err
|
|
164
|
164
|
}
|
|
165
|
165
|
|
|
|
@@ -175,7 +175,7 @@ func (c *Client) BatchSyncTables(ctx context.Context, req *BatchTableSyncRequest
|
|
175
|
175
|
endpoint := "/api/dic-table/batch-sync"
|
|
176
|
176
|
|
|
177
|
177
|
var result ResponseWrapper[BatchTableSyncResponse]
|
|
178
|
|
- if err := c.doRequest(ctx, http.MethodPost, endpoint, req, &result); err != nil {
|
|
|
178
|
+ if err := c.doRequest(ctx, http.MethodPost, endpoint, req, &result, false); err != nil {
|
|
179
|
179
|
return nil, err
|
|
180
|
180
|
}
|
|
181
|
181
|
|
|
|
@@ -191,7 +191,7 @@ func (c *Client) BatchSyncAliases(ctx context.Context, req *BatchAliasSyncReques
|
|
191
|
191
|
endpoint := "/api/alias/batch-sync"
|
|
192
|
192
|
|
|
193
|
193
|
var result ResponseWrapper[BatchAliasSyncResponse]
|
|
194
|
|
- if err := c.doRequest(ctx, http.MethodPost, endpoint, req, &result); err != nil {
|
|
|
194
|
+ if err := c.doRequest(ctx, http.MethodPost, endpoint, req, &result, false); err != nil {
|
|
195
|
195
|
return nil, err
|
|
196
|
196
|
}
|
|
197
|
197
|
|
|
|
@@ -207,7 +207,7 @@ func (c *Client) SaveTableAlias(ctx context.Context, req *TableAliasRequest) (*T
|
|
207
|
207
|
endpoint := "/api/dic-table-alias/save"
|
|
208
|
208
|
|
|
209
|
209
|
var result ResponseWrapper[TableAliasResponse]
|
|
210
|
|
- if err := c.doRequest(ctx, http.MethodPost, endpoint, req, &result); err != nil {
|
|
|
210
|
+ if err := c.doRequest(ctx, http.MethodPost, endpoint, req, &result, false); err != nil {
|
|
211
|
211
|
return nil, err
|
|
212
|
212
|
}
|
|
213
|
213
|
|
|
|
@@ -223,7 +223,7 @@ func (c *Client) SaveTableFieldAlias(ctx context.Context, req *TableFieldAliasRe
|
|
223
|
223
|
endpoint := "/api/dic-table-field-alias/save"
|
|
224
|
224
|
|
|
225
|
225
|
var result ResponseWrapper[TableFieldAliasResponse]
|
|
226
|
|
- if err := c.doRequest(ctx, http.MethodPost, endpoint, req, &result); err != nil {
|
|
|
226
|
+ if err := c.doRequest(ctx, http.MethodPost, endpoint, req, &result, false); err != nil {
|
|
227
|
227
|
return nil, err
|
|
228
|
228
|
}
|
|
229
|
229
|
|
|
|
@@ -239,7 +239,7 @@ func (c *Client) ListTableAliases(ctx context.Context, query *TableAliasQueryReq
|
|
239
|
239
|
endpoint := "/api/dic-table-alias/list"
|
|
240
|
240
|
|
|
241
|
241
|
var result ResponseWrapper[[]TableAliasResponse]
|
|
242
|
|
- if err := c.doRequest(ctx, http.MethodPost, endpoint, query, &result); err != nil {
|
|
|
242
|
+ if err := c.doRequest(ctx, http.MethodPost, endpoint, query, &result, false); err != nil {
|
|
243
|
243
|
return nil, err
|
|
244
|
244
|
}
|
|
245
|
245
|
|
|
|
@@ -259,7 +259,7 @@ func (c *Client) ListTableFieldAliases(ctx context.Context, query *TableFieldAli
|
|
259
|
259
|
endpoint := "/api/dic-table-field-alias/list"
|
|
260
|
260
|
|
|
261
|
261
|
var result ResponseWrapper[[]TableFieldAliasResponse]
|
|
262
|
|
- if err := c.doRequest(ctx, http.MethodPost, endpoint, query, &result); err != nil {
|
|
|
262
|
+ if err := c.doRequest(ctx, http.MethodPost, endpoint, query, &result, false); err != nil {
|
|
263
|
263
|
return nil, err
|
|
264
|
264
|
}
|
|
265
|
265
|
|
|
|
@@ -275,7 +275,7 @@ func (c *Client) ListTableFieldAliases(ctx context.Context, query *TableFieldAli
|
|
275
|
275
|
}
|
|
276
|
276
|
|
|
277
|
277
|
// doRequest 执行HTTP请求
|
|
278
|
|
-func (c *Client) doRequest(ctx context.Context, method, endpoint string, body interface{}, result interface{}) error {
|
|
|
278
|
+func (c *Client) doRequest(ctx context.Context, method, endpoint string, body interface{}, result interface{}, skipAuth bool) error {
|
|
279
|
279
|
// 构建URL
|
|
280
|
280
|
url := c.config.BaseURL + endpoint
|
|
281
|
281
|
|
|
|
@@ -295,9 +295,11 @@ func (c *Client) doRequest(ctx context.Context, method, endpoint string, body in
|
|
295
|
295
|
return WrapError("do_request", "failed to create request", err)
|
|
296
|
296
|
}
|
|
297
|
297
|
|
|
298
|
|
- // 设置认证头
|
|
299
|
|
- if err := c.setAuthHeader(req); err != nil {
|
|
300
|
|
- return err
|
|
|
298
|
+ // 设置认证头(可选)
|
|
|
299
|
+ if !skipAuth {
|
|
|
300
|
+ if err := c.setAuthHeader(req); err != nil {
|
|
|
301
|
+ return err
|
|
|
302
|
+ }
|
|
301
|
303
|
}
|
|
302
|
304
|
|
|
303
|
305
|
// 设置内容类型
|
|
|
@@ -360,6 +362,22 @@ func (c *Client) setAuthHeader(req *http.Request) error {
|
|
360
|
362
|
return nil
|
|
361
|
363
|
}
|
|
362
|
364
|
|
|
|
365
|
+// LoginUser 用户登录(无需认证)
|
|
|
366
|
+func (c *Client) LoginUser(ctx context.Context, req *UserLoginRequest) (string, error) {
|
|
|
367
|
+ endpoint := "/api/login/user"
|
|
|
368
|
+
|
|
|
369
|
+ var result ResponseWrapper[string]
|
|
|
370
|
+ if err := c.doRequest(ctx, http.MethodPost, endpoint, req, &result, true); err != nil {
|
|
|
371
|
+ return "", err
|
|
|
372
|
+ }
|
|
|
373
|
+
|
|
|
374
|
+ if !result.Success {
|
|
|
375
|
+ return "", NewClientError("login_user", fmt.Sprintf("API error: %s", result.Error), nil)
|
|
|
376
|
+ }
|
|
|
377
|
+
|
|
|
378
|
+ return result.Data, nil
|
|
|
379
|
+}
|
|
|
380
|
+
|
|
363
|
381
|
// GetConfig 获取客户端配置
|
|
364
|
382
|
func (c *Client) GetConfig() ClientConfig {
|
|
365
|
383
|
return c.config
|