客户端添加切换租户

This commit is contained in:
cn-kali-team
2026-04-29 18:57:00 +08:00
committed by lyingbug
parent b3898eb101
commit 1e170793b3
4 changed files with 103 additions and 2 deletions
+21 -1
View File
@@ -23,7 +23,7 @@ The client includes the following main functional modules:
```go
import (
"context"
"github.com/Tencent/WeKnora/internal/client"
"github.com/Tencent/WeKnora/client"
"time"
)
@@ -35,6 +35,26 @@ apiClient := client.NewClient(
)
```
### Tenant Configuration
You can set a default tenant with `WithTenantID`; the client will automatically send the `X-Tenant-ID` header:
```go
tenantID := uint64(10000)
apiClient := client.NewClient(
"http://api.example.com",
client.WithToken("your-auth-token"),
client.WithTenantID(tenantID),
)
```
If a single request needs a different tenant, set `TenantID` in the request context. The value can be a `uint64`, `*uint64`, or a numeric string, and it will take precedence over the client default:
```go
ctx := context.WithValue(context.Background(), "TenantID", uint64(10000))
// Pass ctx into any client method to switch to tenant 10000 for that request
```
### Example: Create Knowledge Base and Upload File
```go